-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.py
50 lines (46 loc) · 1.76 KB
/
events.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
class Event(object):
MOUSE_MOVE = 0
MOUSE_WHEEL = 1
PRESS = 2
RELEASE = 3
def __init__(self, _type, key=None, value=None, axis=None):
"""Type of event can be MOUSE_MOVE, MOUSE_WHEEL, PRESS, or RELEASE.
Use value for distances, (MOUSE_MOVE, MOUSE_WHEEL)
Use key for PRESS and RELEASE
"""
self._type = _type
self.value = value
self.key = key
self.axis = axis
class MouseMoveEvent(Event):
"""Move the mouse to a location. Specify x or y axis."""
def __init__(self, axis, value):
axis = axis.lower()
if axis not in ('x', 'y'):
raise ValueError("Axis must be x or y")
super(MouseMoveEvent, self).__init__(_type = Event.MOUSE_MOVE,
axis=axis,
value=value)
def __str__(self):
return "m%s%d" % (self.axis, self.value)
class MouseWheelEvent(Event):
"""Move the mouse wheel a given amount"""
def __init__(self, value):
super(MouseWheelEvent, self).__init__(_type = Event.MOUSE_WHEEL,
value=value)
def __str__(self):
return "mw%d" % self.value
class PressEvent(Event):
"""Press a key. Keys 1,2,3 map to mouse 1,2,3"""
def __init__(self, key):
super(PressEvent, self).__init__(_type = Event.PRESS,
key=key)
def __str__(self):
return "kp%d" % self.key
class ReleaseEvent(Event):
"""Release a key. Keys 1,2,3 map to mouse 1,2,3"""
def __init__(self, key):
super(ReleaseEvent, self).__init__(_type = Event.RELEASE,
key=key)
def __str__(self):
return "kr%d" % self.key