-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.py
71 lines (58 loc) · 1.98 KB
/
mouse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from GuiAPI import QT
if ( QT ):
from PyQt4 import QtCore, QtGui
LEFT_BTN = QtCore.Qt.LeftButton
MIDDLE_BTN = QtCore.Qt.MidButton
RIGHT_BTN = QtCore.Qt.RightButton
#TODO: Determine these events (if necessary)
WHEEL_UP = 4
WHEEL_DOWN = 5
CURR_BUTTONS = 0
def getModState():
'''Reports the current mod state, booleans reporting:
1. if ctrl is down
2. if alt is down
3. if shift is down
'''
mods = QtGui.QApplication.keyboardModifiers()
hasCtrl = bool( mods & QtCore.Qt.ControlModifier )
hasAlt = bool( mods & QtCore.Qt.AltModifier )
hasShift = bool( mods & QtCore.Qt.ShiftModifier )
return hasCtrl, hasAlt, hasShift
def buttonDown( btn ):
'''Infornms the system that a mouse button has been pressed.
@param: btn The identifier of the mouse button that has been pressed.
'''
global CURR_BUTTONS
CURR_BUTTONS |= btn
def buttonUp( btn ):
'''Informs the systemt hat a mouse button has been released.
@param: btn The identifier of the mouse button that has been released.
'''
global CURR_BUTTONS
CURR_BUTTONS &= ~btn
def mouseButtons():
'''Returns the mouse button state.
@returns: An identifier which is a logical or of all pressed mouse buttons.
'''
return CURR_BUTTONS
else:
import pygame
# pygame mouse event button values
NO_BTN = 0
LEFT_BTN = 1
MIDDLE_BTN = 2
RIGHT_BTN = 3
WHEEL_UP = 4
WHEEL_DOWN = 5
def getModState():
'''Reports the current mod state, booleans reporting:
1. if ctrl is down
2. if alt is down
3. if shift is down
'''
mods = pygame.key.get_mods()
hasCtrl = mods & pygame.KMOD_CTRL
hasAlt = mods & pygame.KMOD_ALT
hasShift = mods & pygame.KMOD_SHIFT
return hasCtrl, hasAlt, hasShift