16
from config import config
14
17
from utils import doDelay
15
18
from logging import debugLogger as logger
19
ev = atspi.EventGenerator()
22
doDelay(config.typingDelay)
17
24
def click (x, y, button = 1):
19
Synthesize a mouse button click at (x,y)
21
logger.log("Mouse button %s click at (%s,%s)"%(button,x,y))
22
ev = atspi.EventGenerator()
23
ev.click(x, y, button)
26
Synthesize a mouse button click at (x,y)
28
logger.log("Mouse button %s click at (%s,%s)"%(button,x,y))
29
ev.click(x, y, button)
26
32
def doubleClick (x, y, button = 1):
28
Synthesize a mouse button double-click at (x,y)
30
logger.log("Mouse button %s doubleclick at (%s,%s)"%(button,x,y))
31
ev = atspi.EventGenerator()
32
ev.doubleClick(x,y,button)
34
Synthesize a mouse button double-click at (x,y)
36
logger.log("Mouse button %s doubleclick at (%s,%s)"%(button,x,y))
37
ev.doubleClick(x,y,button)
35
40
def press (x, y, button = 1):
37
Synthesize a mouse button press at (x,y)
39
logger.log("Mouse button %s press at (%s,%s)"%(button,x,y))
40
ev = atspi.EventGenerator()
42
Synthesize a mouse button press at (x,y)
44
logger.log("Mouse button %s press at (%s,%s)"%(button,x,y))
44
48
def release (x, y, button = 1):
46
Synthesize a mouse button release at (x,y)
48
logger.log("Mouse button %s release at (%s,%s)"%(button,x,y))
49
ev = atspi.EventGenerator()
50
ev.release(x,y,button)
50
Synthesize a mouse button release at (x,y)
52
logger.log("Mouse button %s release at (%s,%s)"%(button,x,y))
53
ev.release(x,y,button)
53
56
def absoluteMotion (x, y):
55
Synthesize mouse absolute motion to (x,y)
57
logger.log("Mouse absolute motion to (%s,%s)"%(x,y))
58
ev = atspi.EventGenerator()
59
ev.absoluteMotion(x,y)
58
Synthesize mouse absolute motion to (x,y)
60
logger.log("Mouse absolute motion to (%s,%s)"%(x,y))
61
ev.absoluteMotion(x,y)
62
64
def relativeMotion (x, y):
63
logger.log("Mouse relative motion of (%s,%s)"%(x,y))
64
ev = atspi.EventGenerator()
65
ev.relativeMotion(x,y)
65
logger.log("Mouse relative motion of (%s,%s)"%(x,y))
66
ev.relativeMotion(x,y)
68
69
def drag(fromXY, toXY, button = 1):
70
Synthesize a mouse press, drag, and release on the screen.
71
Wraps atspi.EventGenerator.drag, but with logging and delays.
73
logger.log("Mouse button %s drag from %s to %s"%(button, fromXY, toXY))
74
ev = atspi.EventGenerator()
76
# A direct call to ev.drag doesn't work, delays seem to be needed
77
# for nautilus icon view to work, at least:
80
ev.press (x, y, button)
84
ev.absoluteMotion(x,y)
87
ev.release (x, y, button)
71
Synthesize a mouse press, drag, and release on the screen.
72
Wraps atspi.EventGenerator.drag, but with logging and delays.
74
logger.log("Mouse button %s drag from %s to %s"%(button, fromXY, toXY))
76
# A direct call to ev.drag doesn't work, delays seem to be needed
77
# for nautilus icon view to work, at least:
80
ev.press (x, y, button)
84
ev.absoluteMotion(x,y)
87
ev.release (x, y, button)
90
90
def typeText(string):
92
Types the specified string, one character at a time.
94
ev = atspi.EventGenerator()
95
ev.injectKeyboardString(string)
92
Types the specified string, one character at a time.
94
if not isinstance(string, unicode):
95
string = string.decode('utf-8')
99
def __buildKeyStringsDict(keySymsDict):
102
iter = keySymsDict.iteritems()
107
if item[1] in syms.keys():
108
syms[item[1]].append(item[0])
109
print item[1], syms[item[1]]
111
try: syms[item[1]] = [item[0]]
112
except TypeError: pass
115
if not keyStringsDict.has_key(item[1]):
116
keyStringsDict[item[1]] = item[0]
117
except TypeError: pass
118
except StopIteration:
119
return keyStringsDict
121
keySyms = gtk.keysyms.__dict__
122
keyStrings = __buildKeyStringsDict(keySyms)
128
'control' : 'Control_L',
129
'ctrl' : 'Control_L',
133
'pageup' : 'Page_Up',
134
'pagedown' : 'Page_Down',
140
def keySymToUniChar(keySym):
141
i = gtk.gdk.keyval_to_unicode(keySym)
142
if i: UniChar = unichr(i)
146
def uniCharToKeySym(uniChar):
148
keySym = gtk.gdk.unicode_to_keyval(i)
103
151
def pressKey(keyName):
105
Presses (and releases) the key specified by keyName.
106
keyName is the English name of the key as seen on the keyboard. Ex: 'enter'
107
Names are looked up in the keySyms dict.
109
ev = atspi.EventGenerator()
110
keySym = keySyms[keyName.lower()]
111
ev.generateKeyboardEvent(keySym, "", atspi.SPI_KEY_SYM)
153
Presses (and releases) the key specified by keyName.
154
keyName is the English name of the key as seen on the keyboard. Ex: 'enter'
155
Names are looked up in the keySyms dict. If they are not found there,
156
they are looked up by uniCharToKeySym().
159
keyName = keySymAliases.get(keyName.lower(), keyName)
160
keySym = keySyms[keyName]
162
try: keySym = uniCharToKeySym(keyName)
163
except TypeError: raise KeyError, keyName
164
ev.generateKeyboardEvent(keySym, "", atspi.SPI_KEY_SYM)
167
def keyCombo(comboString):
169
Generates the appropriate keyboard events to simulate a user pressing the
170
specified key combination.
172
comboString is the representation of the key combo to be generated.
173
e.g. '<Control><Alt>p' or '<Control><Shift>PageUp' or '<Control>q'
176
for s in comboString.split('<'):
178
for S in s.split('>'):
180
S = keySymAliases.get(S.lower(), S)
183
if not keySyms.has_key(s):
184
raise ValueError, "Cannot find key %s" % s
186
ev.generateKeyCombo(strings)