├── AutoHotPy.py ├── COPYING ├── COPYING.LESSER ├── Example1-GameCombo.py ├── Example10-Macros6 - Record keyboard only.py ├── Example11-Joystick to ALT F4.py ├── Example2-MultipleKeys.py ├── Example3-MouseButtons.py ├── Example4-MouseMovement.py ├── Example5-Macros.py ├── Example6-Macros2 - Gaming macros.py ├── Example7-Macros3 - Saving macro to file.py ├── Example8-Macros4 - Auto-repeating macros.py ├── Example9-Macros5 - Record mouse only.py ├── InterceptionWrapper.py ├── README.md └── scancodes.ods /AutoHotPy.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | from InterceptionWrapper import * 21 | import collections,time,threading,queue,copy,ctypes 22 | 23 | 24 | class FunctionRunner(threading.Thread): 25 | def __init__(self,queue): 26 | threading.Thread.__init__(self) 27 | self.queue = queue 28 | def run(self): 29 | while True: 30 | #grabs a function from queue 31 | task = self.queue.get() 32 | 33 | #run it 34 | task.run() 35 | 36 | #signals to queue job is done 37 | self.queue.task_done() 38 | 39 | class Task(object): 40 | def __init__(self,autohotpy,f,param): 41 | self.function = f 42 | self.arg1 = autohotpy 43 | self.arg2 = param 44 | def run(self): 45 | self.function(self.arg1,self.arg2) 46 | 47 | class Key(object): 48 | def __init__(self,auto,code,str_repr,*args): 49 | self.auto = auto 50 | self.code = code 51 | if (len(args) != 0): 52 | self.state = args[0] 53 | else: 54 | self.state = 0 55 | self.key_id = auto.get_key_id(self.code, self.state) 56 | self.string_representation = str_repr 57 | 58 | def get_id(self): 59 | return self.key_id 60 | 61 | def up(self): 62 | up = InterceptionKeyStroke() 63 | up.code = self.code 64 | up.state = InterceptionKeyState.INTERCEPTION_KEY_UP | self.state 65 | self.auto.sendToDefaultKeyboard(up) 66 | 67 | def press(self): 68 | event = InterceptionKeyStroke() 69 | event.code = self.code 70 | event.state = InterceptionKeyState.INTERCEPTION_KEY_DOWN | self.state 71 | self.auto.sendToDefaultKeyboard(event) 72 | self.auto.sleep() 73 | event.state = InterceptionKeyState.INTERCEPTION_KEY_UP | self.state 74 | self.auto.sendToDefaultKeyboard(event) 75 | 76 | def down(self): 77 | down = InterceptionKeyStroke() 78 | down.code = self.code 79 | down.state = InterceptionKeyState.INTERCEPTION_KEY_DOWN | self.state 80 | self.auto.sendToDefaultKeyboard(down) 81 | 82 | def isPressed(self): 83 | return bool(not(self.auto.getKeyboardState(self.code,self.state) & InterceptionKeyState.INTERCEPTION_KEY_UP)) 84 | 85 | def __int__(self): 86 | return int(self.code) 87 | 88 | def __str__(self): 89 | return self.string_representation 90 | 91 | class AutoHotPy(object): 92 | 93 | def __init__(self): 94 | self.exit_configured = False 95 | self.user32 = ctypes.windll.user32 96 | 97 | #configure user32 98 | self.user32.GetCursorPos.restype = ctypes.POINTER(Point) 99 | #default interval between keypress 100 | self.default_interval = 0.01 101 | #Threads queue 102 | self.kb_queue = queue.Queue() 103 | self.mouse_queue = queue.Queue() 104 | self.macro_queue = queue.Queue() 105 | 106 | # Handlers 107 | self.keyboard_handler_down = collections.defaultdict(self.__default_element) 108 | self.keyboard_handler_hold = collections.defaultdict(self.__default_element) 109 | self.keyboard_handler_up = collections.defaultdict(self.__default_element) 110 | self.mouse_handler_hold = collections.defaultdict(self.__default_element) 111 | self.mouse_handler = collections.defaultdict(self.__default_element) 112 | self.mouse_move_handler = None 113 | self.keyboard_state = collections.defaultdict(self.__default_kb_element) 114 | self.mouse_state = collections.defaultdict(self.__default_element) 115 | self.loopingCall = None 116 | 117 | #are we recording a macro? Not yet... 118 | self.recording_macro = False 119 | self.enable_mouse_macro = True 120 | self.enable_kb_macro = True 121 | self.last_macro = [] 122 | self.keys = collections.defaultdict(self.__default_kb_element) 123 | 124 | # Default key scancodes (you can send your own anyway) 125 | # WARNING! Most of these depend on the keyboard implementation!!!! 126 | self.ESC=Key(self,0x1,"ESC") 127 | self.N1=Key(self,0x2,"N1") 128 | self.N2=Key(self,0x3,"N2") 129 | self.N3=Key(self,0x4,"N3") 130 | self.N4=Key(self,0x5,"N4") 131 | self.N5=Key(self,0x6,"N5") 132 | self.N6=Key(self,0x7,"N6") 133 | self.N7=Key(self,0x8,"N7") 134 | self.N8=Key(self,0x9,"N8") 135 | self.N9=Key(self,0x0A,"N9") 136 | self.N0=Key(self,0x0B,"N0") 137 | self.DASH=Key(self,0x0C,"DASH") 138 | #self.Err:520=Key(self,0x0D) 139 | self.BACKSPACE=Key(self,0x0E,"BACKSPACE") 140 | self.TAB=Key(self,0x0F,"TAB") 141 | self.Q=Key(self,0x10,"Q") 142 | self.W=Key(self,0x11,"W") 143 | self.E=Key(self,0x12,"E") 144 | self.R=Key(self,0x13,"R") 145 | self.T=Key(self,0x14,"T") 146 | self.Y=Key(self,0x15,"Y") 147 | self.U=Key(self,0x16,"U") 148 | self.I=Key(self,0x17,"I") 149 | self.O=Key(self,0x18,"O") 150 | self.P=Key(self,0x19,"P") 151 | self.BRACKET_LEFT=Key(self,0x1A,"BRACKET_LEFT") 152 | self.BRACKET_RIGHT=Key(self,0x1B,"BRACKET_RIGHT") 153 | self.ENTER=Key(self,0x1C,"ENTER") 154 | self.LEFT_CTRL=Key(self,0x1D,"LEFT_CTRL") 155 | self.RIGHT_CTRL=Key(self,0x1D,"RIGHT_CTRL", InterceptionKeyState.INTERCEPTION_KEY_E0) 156 | self.A=Key(self,0x1E,"A") 157 | self.S=Key(self,0x1F,"S") 158 | self.D=Key(self,0x20,"D") 159 | self.F=Key(self,0x21,"F") 160 | self.G=Key(self,0x22,"G") 161 | self.H=Key(self,0x23,"H") 162 | self.J=Key(self,0x24,"J") 163 | self.K=Key(self,0x25,"K") 164 | self.L=Key(self,0x26,"L") 165 | self.SEMICOLON=Key(self,0x27,"SEMICOLON") 166 | self.APOSTROPHE=Key(self,0x28,"APOSTROPHE") 167 | self.GRAVE_ACCENT=Key(self,0x29,"GRAVE_ACCENT") 168 | self.LEFT_SHIFT=Key(self,0x2A,"LEFT_SHIFT") 169 | self.BACKSLASH=Key(self,0x2B,"BACKSLASH") 170 | self.Z=Key(self,0x2C,"Z") 171 | self.X=Key(self,0x2D,"X") 172 | self.C=Key(self,0x2E,"C") 173 | self.V=Key(self,0x2F,"V") 174 | self.B=Key(self,0x30,"B") 175 | self.N=Key(self,0x31,"N") 176 | self.M=Key(self,0x32,"M") 177 | self.COMMA=Key(self,0x33,"COMMA") 178 | self.DOT=Key(self,0x34,"DOT") 179 | self.SLASH=Key(self,0x35,"SLASH") 180 | self.RIGHT_SHIFT=Key(self,0x36,"RIGHT_SHIFT") 181 | self.PRINT_SCREEN=Key(self,0x37,"PRINT_SCREEN", InterceptionKeyState.INTERCEPTION_KEY_E0) 182 | self.LEFT_ALT=Key(self,0x38,"LEFT_ALT") 183 | self.RIGHT_ALT=Key(self,0x38,"RIGHT_ALT", InterceptionKeyState.INTERCEPTION_KEY_E0) 184 | self.SPACE=Key(self,0x39,"SPACE") 185 | self.CAPSLOCK=Key(self,0x3A,"CAPSLOCK") 186 | self.F1=Key(self,0x3B,"F1") 187 | self.F2=Key(self,0x3C,"F2") 188 | self.F3=Key(self,0x3D,"F3") 189 | self.F4=Key(self,0x3E,"F4") 190 | self.F5=Key(self,0x3F,"F5") 191 | self.F6=Key(self,0x40,"F6") 192 | self.F7=Key(self,0x41,"F7") 193 | self.F8=Key(self,0x42,"F8") 194 | self.F9=Key(self,0x43,"F9") 195 | self.F10=Key(self,0x44,"F10") 196 | self.NUMLOCK=Key(self,0x45,"NUMLOCK") 197 | self.SCROLLLOCK=Key(self,0x46,"SCROLLLOCK") 198 | self.HOME=Key(self,0x47,"HOME") 199 | self.UP_ARROW=Key(self,0x48,"UP_ARROW", InterceptionKeyState.INTERCEPTION_KEY_E0) 200 | self.PAGE_UP=Key(self,0x49,"PAGE_UP", InterceptionKeyState.INTERCEPTION_KEY_E0) 201 | self.DASH_NUM=Key(self,0x4A,"DASH_NUM") 202 | self.LEFT_ARROW=Key(self,0x4B,"LEFT_ARROW", InterceptionKeyState.INTERCEPTION_KEY_E0) 203 | self.NUMERIC_5 =Key(self,0x4C,"NUMERIC_5") 204 | self.RIGHT_ARROW=Key(self,0x4D,"RIGHT_ARROW", InterceptionKeyState.INTERCEPTION_KEY_E0) 205 | self.PLUS=Key(self,0x4E,"PLUS") 206 | self.END=Key(self,0x4F,"END", InterceptionKeyState.INTERCEPTION_KEY_E0) 207 | self.DOWN_ARROW=Key(self,0x50,"DOWN_ARROW", InterceptionKeyState.INTERCEPTION_KEY_E0) 208 | self.PAGE_DOWN=Key(self,0x51,"PAGE_DOWN", InterceptionKeyState.INTERCEPTION_KEY_E0) 209 | self.INSERT=Key(self,0x52,"INSERT", InterceptionKeyState.INTERCEPTION_KEY_E0) 210 | self.DELETE=Key(self,0x53,"DELETE", InterceptionKeyState.INTERCEPTION_KEY_E0) 211 | self.SHIFT_F1=Key(self,0x54,"SHIFT_F1") 212 | self.SHIFT_F2=Key(self,0x55,"SHIFT_F2") 213 | self.SHIFT_F3=Key(self,0x56,"SHIFT_F3") 214 | #self.SHIFT_F4=Key(self,0x57) 215 | #self.SHIFT_F5=Key(self,0x58) 216 | self.F11=Key(self,0x57,"F11") #these are not common. and might vary from one keyboard to another 217 | self.F12=Key(self,0x58,"F12") 218 | self.SHIFT_F6=Key(self,0x59,"SHIFT_F6") 219 | self.SHIFT_F7=Key(self,0x5A,"SHIFT_F7") 220 | self.SHIFT_F8=Key(self,0x5B,"SHIFT_F8") 221 | self.SYSTEM=Key(self,0x5B,"SYSTEM", InterceptionKeyState.INTERCEPTION_KEY_E0) #commonly known as windows key 222 | self.SHIFT_F9=Key(self,0x5C,"SHIFT_F9") 223 | self.SHIFT_F10=Key(self,0x5D,"SHIFT_F10") 224 | self.CTRL_F1=Key(self,0x5E,"CTRL_F1") 225 | self.CTRL_F2=Key(self,0x5F,"CTRL_F2") 226 | self.CTRL_F3=Key(self,0x60,"CTRL_F3") 227 | self.CTRL_F4=Key(self,0x61,"CTRL_F4") 228 | self.CTRL_F5=Key(self,0x62,"CTRL_F5") 229 | self.CTRL_F6=Key(self,0x63,"CTRL_F6") 230 | self.CTRL_F7=Key(self,0x64,"CTRL_F7") 231 | self.CTRL_F8=Key(self,0x65,"CTRL_F8") 232 | self.CTRL_F9=Key(self,0x66,"CTRL_F9") 233 | self.CTRL_F10=Key(self,0x67,"CTRL_F10") 234 | self.ALT_F1=Key(self,0x68,"ALT_F1") 235 | self.ALT_F2=Key(self,0x69,"ALT_F2") 236 | self.ALT_F3=Key(self,0x6A,"ALT_F3") 237 | self.ALT_F4=Key(self,0x6B,"ALT_F4") 238 | self.ALT_F5=Key(self,0x6C,"ALT_F5") 239 | self.ALT_F6=Key(self,0x6D,"ALT_F6") 240 | self.ALT_F7=Key(self,0x6E,"ALT_F7") 241 | self.ALT_F8=Key(self,0x6F,"ALT_F8") 242 | self.ALT_F9=Key(self,0x70,"ALT_F9") 243 | self.ALT_F10=Key(self,0x71,"ALT_F10") 244 | self.CTRL_PRINT_SCREEN=Key(self,0x72,"CTRL_PRINT_SCREEN") 245 | self.CTRL_LEFT_ARROW=Key(self,0x73,"CTRL_LEFT_ARROW") 246 | self.CTRL_RIGHT_ARROW=Key(self,0x74,"CTRL_RIGHT_ARROW") 247 | self.CTRL_END=Key(self,0x75,"CTRL_END") 248 | self.CTRL_PAGE_DOWN=Key(self,0x76,"CTRL_PAGE_DOWN") 249 | self.CTRL_HOME=Key(self,0x77,"CTRL_HOME") 250 | self.ALT_1=Key(self,0x78,"ALT_1") 251 | self.ALT_2=Key(self,0x79,"ALT_2") 252 | self.ALT_3=Key(self,0x7A,"ALT_3") 253 | self.ALT_4=Key(self,0x7B,"ALT_4") 254 | self.ALT_5=Key(self,0x7C,"ALT_5") 255 | self.ALT_6=Key(self,0x7D,"ALT_6") 256 | self.ALT_7=Key(self,0x7E,"ALT_7") 257 | self.ALT_8=Key(self,0x7F,"ALT_8") 258 | self.ALT_9=Key(self,0x80,"ALT_9") 259 | self.ALT_0=Key(self,0x81,"ALT_0") 260 | self.ALT_DASH=Key(self,0x82,"ALT_DASH") 261 | self.ALT_EQUALS=Key(self,0x82,"ALT_EQUALS") 262 | self.CTRL_PAGE_UP=Key(self,0x84,"CTRL_PAGE_UP") 263 | #self.F11=Key(self,0x85) 264 | #self.F12=Key(self,0x86) 265 | self.SHIFT_F11=Key(self,0x87,"SHIFT_F11") 266 | self.SHIFT_F12=Key(self,0x88,"SHIFT_F12") 267 | self.CTRL_F11=Key(self,0x89,"CTRL_F11") 268 | self.CTRL_F12=Key(self,0x8A,"CTRL_F12") 269 | self.ALT_F11=Key(self,0x8B,"ALT_F11") 270 | self.ALT_F12=Key(self,0x8C,"ALT_F12") 271 | self.CTRL_UP_ARROW=Key(self,0x8C,"CTRL_UP_ARROW") 272 | self.CTRL_DASH_NUM=Key(self,0x8E,"CTRL_DASH_NUM") 273 | self.CTRL_5_NUM=Key(self,0x8F,"CTRL_5_NUM") 274 | self.CTRL_PLUS_NUM=Key(self,0x90,"CTRL_PLUS_NUM") 275 | self.CTRL_DOWN_ARROW=Key(self,0x91,"CTRL_DOWN_ARROW") 276 | self.CTRL_INSERT=Key(self,0x92,"CTRL_INSERT") 277 | self.CTRL_DELETE=Key(self,0x93,"CTRL_DELETE") 278 | self.CTRL_TAB=Key(self,0x94,"CTRL_TAB") 279 | self.CTRL_SLASH_NUM=Key(self,0x95,"CTRL_SLASH_NUM") 280 | self.CTRL_ASTERISK_NUM=Key(self,0x96,"CTRL_ASTERISK_NUM") 281 | self.ALT_HOME=Key(self,0x97,"ALT_HOME") 282 | self.ALT_UP_ARROW=Key(self,0x98,"ALT_UP_ARROW") 283 | self.ALT_PAGE_UP=Key(self,0x99,"ALT_PAGE_UP") 284 | #self. =Key(self,0x9A) 285 | self.ALT_LEFT_ARROW=Key(self,0x9B,"ALT_LEFT_ARROW") 286 | #self. =Key(self,0x9C) 287 | self.ALT_RIGHT_ARROW=Key(self,0x9D,"ALT_RIGHT_ARROW") 288 | #self. =Key(self,0x9E) 289 | self.ALT_END=Key(self,0x9F,"ALT_END") 290 | self.ALT_DOWN_ARROW=Key(self,0xA0,"ALT_DOWN_ARROW") 291 | self.ALT_PAGE_DOWN=Key(self,0xA1,"ALT_PAGE_DOWN") 292 | self.ALT_INSERT=Key(self,0xA2,"ALT_INSERT") 293 | self.ALT_DELETE=Key(self,0xA3,"ALT_DELETE") 294 | self.ALT_SLASH_NUM=Key(self,0xA4,"ALT_SLASH_NUM") 295 | self.ALT_TAB=Key(self,0xA5,"ALT_TAB") 296 | self.ALT_ENTER_NUM=Key(self,0xA6,"ALT_ENTER_NUM") 297 | 298 | #lets create a dictionary with the keys 299 | #this is used when we save a macro to a file 300 | self.keys[self.ESC.get_id()]=self.ESC 301 | self.keys[self.N1.get_id()]=self.N1 302 | self.keys[self.N2.get_id()]=self.N2 303 | self.keys[self.N3.get_id()]=self.N3 304 | self.keys[self.N4.get_id()]=self.N4 305 | self.keys[self.N5.get_id()]=self.N5 306 | self.keys[self.N6.get_id()]=self.N6 307 | self.keys[self.N7.get_id()]=self.N7 308 | self.keys[self.N8.get_id()]=self.N8 309 | self.keys[self.N9.get_id()]=self.N9 310 | self.keys[self.N0.get_id()]=self.N0 311 | self.keys[self.DASH.get_id()]=self.DASH 312 | #self.keys[self.Err:520.get_id()]=self. 313 | self.keys[self.BACKSPACE.get_id()]=self.BACKSPACE 314 | self.keys[self.TAB.get_id()]=self.TAB 315 | self.keys[self.Q.get_id()]=self.Q 316 | self.keys[self.W.get_id()]=self.W 317 | self.keys[self.E.get_id()]=self.E 318 | self.keys[self.R.get_id()]=self.R 319 | self.keys[self.T.get_id()]=self.T 320 | self.keys[self.Y.get_id()]=self.Y 321 | self.keys[self.U.get_id()]=self.U 322 | self.keys[self.I.get_id()]=self.I 323 | self.keys[self.O.get_id()]=self.O 324 | self.keys[self.P.get_id()]=self.P 325 | self.keys[self.BRACKET_LEFT.get_id()]=self.BRACKET_LEFT 326 | self.keys[self.BRACKET_RIGHT.get_id()]=self.BRACKET_RIGHT 327 | self.keys[self.ENTER.get_id()]=self.ENTER 328 | self.keys[self.LEFT_CTRL.get_id()]=self.LEFT_CTRL 329 | self.keys[self.RIGHT_CTRL.get_id()]=self.RIGHT_CTRL 330 | self.keys[self.A.get_id()]=self.A 331 | self.keys[self.S.get_id()]=self.S 332 | self.keys[self.D.get_id()]=self.D 333 | self.keys[self.F.get_id()]=self.F 334 | self.keys[self.G.get_id()]=self.G 335 | self.keys[self.H.get_id()]=self.H 336 | self.keys[self.J.get_id()]=self.J 337 | self.keys[self.K.get_id()]=self.K 338 | self.keys[self.L.get_id()]=self.L 339 | self.keys[self.SEMICOLON.get_id()]=self.SEMICOLON 340 | self.keys[self.APOSTROPHE.get_id()]=self.APOSTROPHE 341 | self.keys[self.GRAVE_ACCENT.get_id()]=self.GRAVE_ACCENT 342 | self.keys[self.LEFT_SHIFT.get_id()]=self.LEFT_SHIFT 343 | self.keys[self.BACKSLASH.get_id()]=self.BACKSLASH 344 | self.keys[self.Z.get_id()]=self.Z 345 | self.keys[self.X.get_id()]=self.X 346 | self.keys[self.C.get_id()]=self.C 347 | self.keys[self.V.get_id()]=self.V 348 | self.keys[self.B.get_id()]=self.B 349 | self.keys[self.N.get_id()]=self.N 350 | self.keys[self.M.get_id()]=self.M 351 | self.keys[self.COMMA.get_id()]=self.COMMA 352 | self.keys[self.DOT.get_id()]=self.DOT 353 | self.keys[self.SLASH.get_id()]=self.SLASH 354 | self.keys[self.RIGHT_SHIFT.get_id()]=self.RIGHT_SHIFT 355 | self.keys[self.PRINT_SCREEN.get_id()]=self.PRINT_SCREEN 356 | self.keys[self.LEFT_ALT.get_id()]=self.LEFT_ALT 357 | self.keys[self.RIGHT_ALT.get_id()]=self.RIGHT_ALT 358 | self.keys[self.SPACE.get_id()]=self.SPACE 359 | self.keys[self.CAPSLOCK.get_id()]=self.CAPSLOCK 360 | self.keys[self.F1.get_id()]=self.F1 361 | self.keys[self.F2.get_id()]=self.F2 362 | self.keys[self.F3.get_id()]=self.F3 363 | self.keys[self.F4.get_id()]=self.F4 364 | self.keys[self.F5.get_id()]=self.F5 365 | self.keys[self.F6.get_id()]=self.F6 366 | self.keys[self.F7.get_id()]=self.F7 367 | self.keys[self.F8.get_id()]=self.F8 368 | self.keys[self.F9.get_id()]=self.F9 369 | self.keys[self.F10.get_id()]=self.F10 370 | self.keys[self.NUMLOCK.get_id()]=self.NUMLOCK 371 | self.keys[self.SCROLLLOCK.get_id()]=self.SCROLLLOCK 372 | self.keys[self.HOME.get_id()]=self.HOME 373 | self.keys[self.UP_ARROW.get_id()]=self.UP_ARROW 374 | self.keys[self.PAGE_UP.get_id()]=self.PAGE_UP 375 | self.keys[self.DASH_NUM.get_id()]=self.DASH_NUM 376 | self.keys[self.LEFT_ARROW.get_id()]=self.LEFT_ARROW 377 | self.keys[self.NUMERIC_5 .get_id()]=self.NUMERIC_5 378 | self.keys[self.RIGHT_ARROW.get_id()]=self.RIGHT_ARROW 379 | self.keys[self.PLUS.get_id()]=self.PLUS 380 | self.keys[self.END.get_id()]=self.END 381 | self.keys[self.DOWN_ARROW.get_id()]=self.DOWN_ARROW 382 | self.keys[self.PAGE_DOWN.get_id()]=self.PAGE_DOWN 383 | self.keys[self.INSERT.get_id()]=self.INSERT 384 | self.keys[self.DELETE.get_id()]=self.DELETE 385 | self.keys[self.SHIFT_F1.get_id()]=self.SHIFT_F1 386 | self.keys[self.SHIFT_F2.get_id()]=self.SHIFT_F2 387 | self.keys[self.SHIFT_F3.get_id()]=self.SHIFT_F3 388 | #self.keys[self.SHIFT_F4.get_id()]=self.SHIFT_F4 389 | #self.keys[self.SHIFT_F5.get_id()]=self.SHIFT_F5 390 | self.keys[self.F11.get_id()]=self.F11 #these are not common. and might vary from one keyboard to another 391 | self.keys[self.F12.get_id()]=self.F12 392 | self.keys[self.SHIFT_F6.get_id()]=self.SHIFT_F6 393 | self.keys[self.SHIFT_F7.get_id()]=self.SHIFT_F7 394 | self.keys[self.SHIFT_F8.get_id()]=self.SHIFT_F8 395 | self.keys[self.SYSTEM.get_id()]=self.SYSTEM #commonly known as windows key 396 | self.keys[self.SHIFT_F9.get_id()]=self.SHIFT_F9 397 | self.keys[self.SHIFT_F10.get_id()]=self.SHIFT_F10 398 | self.keys[self.CTRL_F1.get_id()]=self.CTRL_F1 399 | self.keys[self.CTRL_F2.get_id()]=self.CTRL_F2 400 | self.keys[self.CTRL_F3.get_id()]=self.CTRL_F3 401 | self.keys[self.CTRL_F4.get_id()]=self.CTRL_F4 402 | self.keys[self.CTRL_F5.get_id()]=self.CTRL_F5 403 | self.keys[self.CTRL_F6.get_id()]=self.CTRL_F6 404 | self.keys[self.CTRL_F7.get_id()]=self.CTRL_F7 405 | self.keys[self.CTRL_F8.get_id()]=self.CTRL_F8 406 | self.keys[self.CTRL_F9.get_id()]=self.CTRL_F9 407 | self.keys[self.CTRL_F10.get_id()]=self.CTRL_F10 408 | self.keys[self.ALT_F1.get_id()]=self.ALT_F1 409 | self.keys[self.ALT_F2.get_id()]=self.ALT_F2 410 | self.keys[self.ALT_F3.get_id()]=self.ALT_F3 411 | self.keys[self.ALT_F4.get_id()]=self.ALT_F4 412 | self.keys[self.ALT_F5.get_id()]=self.ALT_F5 413 | self.keys[self.ALT_F6.get_id()]=self.ALT_F6 414 | self.keys[self.ALT_F7.get_id()]=self.ALT_F7 415 | self.keys[self.ALT_F8.get_id()]=self.ALT_F8 416 | self.keys[self.ALT_F9.get_id()]=self.ALT_F9 417 | self.keys[self.ALT_F10.get_id()]=self.ALT_F10 418 | self.keys[self.CTRL_PRINT_SCREEN.get_id()]=self.CTRL_PRINT_SCREEN 419 | self.keys[self.CTRL_LEFT_ARROW.get_id()]=self.CTRL_LEFT_ARROW 420 | self.keys[self.CTRL_RIGHT_ARROW.get_id()]=self.CTRL_RIGHT_ARROW 421 | self.keys[self.CTRL_END.get_id()]=self.CTRL_END 422 | self.keys[self.CTRL_PAGE_DOWN.get_id()]=self.CTRL_PAGE_DOWN 423 | self.keys[self.CTRL_HOME.get_id()]=self.CTRL_HOME 424 | self.keys[self.ALT_1.get_id()]=self.ALT_1 425 | self.keys[self.ALT_2.get_id()]=self.ALT_2 426 | self.keys[self.ALT_3.get_id()]=self.ALT_3 427 | self.keys[self.ALT_4.get_id()]=self.ALT_4 428 | self.keys[self.ALT_5.get_id()]=self.ALT_5 429 | self.keys[self.ALT_6.get_id()]=self.ALT_6 430 | self.keys[self.ALT_7.get_id()]=self.ALT_7 431 | self.keys[self.ALT_8.get_id()]=self.ALT_8 432 | self.keys[self.ALT_9.get_id()]=self.ALT_9 433 | self.keys[self.ALT_0.get_id()]=self.ALT_0 434 | self.keys[self.ALT_DASH.get_id()]=self.ALT_DASH 435 | self.keys[self.ALT_EQUALS.get_id()]=self.ALT_EQUALS 436 | self.keys[self.CTRL_PAGE_UP.get_id()]=self.CTRL_PAGE_UP 437 | #self.keys[self.F11.get_id()]=self. 438 | #self.keys[self.F12.get_id()]=self. 439 | self.keys[self.SHIFT_F11.get_id()]=self.SHIFT_F11 440 | self.keys[self.SHIFT_F12.get_id()]=self.SHIFT_F12 441 | self.keys[self.CTRL_F11.get_id()]=self.CTRL_F11 442 | self.keys[self.CTRL_F12.get_id()]=self.CTRL_F12 443 | self.keys[self.ALT_F11.get_id()]=self.ALT_F11 444 | self.keys[self.ALT_F12.get_id()]=self.ALT_F12 445 | self.keys[self.CTRL_UP_ARROW.get_id()]=self.CTRL_UP_ARROW 446 | self.keys[self.CTRL_DASH_NUM.get_id()]=self.CTRL_DASH_NUM 447 | self.keys[self.CTRL_5_NUM.get_id()]=self.CTRL_5_NUM 448 | self.keys[self.CTRL_PLUS_NUM.get_id()]=self.CTRL_PLUS_NUM 449 | self.keys[self.CTRL_DOWN_ARROW.get_id()]=self.CTRL_DOWN_ARROW 450 | self.keys[self.CTRL_INSERT.get_id()]=self.CTRL_INSERT 451 | self.keys[self.CTRL_DELETE.get_id()]=self.CTRL_DELETE 452 | self.keys[self.CTRL_TAB.get_id()]=self.CTRL_TAB 453 | self.keys[self.CTRL_SLASH_NUM.get_id()]=self.CTRL_SLASH_NUM 454 | self.keys[self.CTRL_ASTERISK_NUM.get_id()]=self.CTRL_ASTERISK_NUM 455 | self.keys[self.ALT_HOME.get_id()]=self.ALT_HOME 456 | self.keys[self.ALT_UP_ARROW.get_id()]=self.ALT_UP_ARROW 457 | self.keys[self.ALT_PAGE_UP.get_id()]=self.ALT_PAGE_UP 458 | #self.keys[self. .get_id()]=self. 459 | self.keys[self.ALT_LEFT_ARROW.get_id()]=self.ALT_LEFT_ARROW 460 | #self.keys[self. .get_id()]=self. 461 | self.keys[self.ALT_RIGHT_ARROW.get_id()]=self.ALT_RIGHT_ARROW 462 | #self.keys[self. .get_id()]=self. 463 | self.keys[self.ALT_END.get_id()]=self.ALT_END 464 | self.keys[self.ALT_DOWN_ARROW.get_id()]=self.ALT_DOWN_ARROW 465 | self.keys[self.ALT_PAGE_DOWN.get_id()]=self.ALT_PAGE_DOWN 466 | self.keys[self.ALT_INSERT.get_id()]=self.ALT_INSERT 467 | self.keys[self.ALT_DELETE.get_id()]=self.ALT_DELETE 468 | self.keys[self.ALT_SLASH_NUM.get_id()]=self.ALT_SLASH_NUM 469 | self.keys[self.ALT_TAB.get_id()]=self.ALT_TAB 470 | self.keys[self.ALT_ENTER_NUM.get_id()]=self.ALT_ENTER_NUM 471 | 472 | def get_key_id(self, code, state): 473 | """ 474 | a key id is a combination of the code and the state ignoring 475 | up and down bits. This is done to consider E0 and E1 states 476 | to differentiate left and right control keys, arrows from numbers, etc 477 | """ 478 | return int("0x%s%s"% (hex(code).replace('0x', ''),hex(state & 0xFE).replace('0x', '')),16) 479 | 480 | def __default_kb_element(self): 481 | """ 482 | if there is not state, it has never been pressed, so it's up 483 | """ 484 | return InterceptionKeyState.INTERCEPTION_KEY_UP 485 | 486 | def __default_element(self): 487 | """ 488 | Used to return None instead of a key exception for maps 489 | """ 490 | return None 491 | 492 | def __null_handler(self,interception,event): 493 | """ 494 | Used as a null handler to disable events like "hold" 495 | """ 496 | return None 497 | 498 | def runMacro(self, autohotpy, macro_list): 499 | """ 500 | go trough the events list and run the events in the specified time 501 | run this in another thread or you will block the execution 502 | autohotpy is in the parameters because I wanted to execute this as a task 503 | """ 504 | 505 | def getTimeDifference(old,new): 506 | if (old == 0): 507 | return 0 508 | return new-old 509 | last_time=0 510 | #removing invalid events that the macro accidentally stores 511 | #startkey UP is pressed as first char 512 | #startkey DOWN is pressed as last char 513 | macro_valid_elements = macro_list[1:len(macro_list)-1] 514 | for event in macro_valid_elements: 515 | self.sleep(getTimeDifference(last_time,event[0])) #wait before firing the event 516 | last_time = event[0] 517 | if (isinstance(event[1],InterceptionMouseStroke)): 518 | # print("Stroke state:" + str(hex(event[1].state))) 519 | # print("Stroke flags:" + str(hex(event[1].flags))) 520 | # print("Stroke information:" + str(hex(event[1].information))) 521 | # print("Stroke rolling:" + str(hex(event[1].rolling))) 522 | # print("Stroke x:" + str(hex(event[1].x))) 523 | # print("Stroke y:" + str(hex(event[1].y))) 524 | self.sendToDefaultMouse(event[1]) 525 | elif(isinstance(event[1],InterceptionKeyStroke)): 526 | # print("Stroke scancode:" + str(hex(event[1].code))) 527 | # print("Stroke state:" + str(hex(event[1].state))) 528 | self.sendToDefaultKeyboard(event[1]) 529 | 530 | def sleep(self, *args): 531 | """ 532 | Sleep. If no parameters are sent, default_interval is assumed. 533 | useful for waiting between keypress. 534 | """ 535 | if (len(args) == 0): 536 | interval = self.default_interval 537 | else: 538 | interval=args[0] 539 | 540 | time.sleep(interval) 541 | 542 | def start(self): 543 | if (not self.exit_configured): 544 | raise Exception("Configure a way to close the process before starting") 545 | #Load the dll and setup the required functions 546 | self.interception = InterceptionWrapper() 547 | # Setup context 548 | self.context = self.interception.interception_create_context() 549 | if (self.context == None): 550 | raise Exception("Interception driver not installed!\nInstall required drivers to continue.") 551 | self.running = True 552 | 553 | # Setup filters. 554 | self.interception.interception_set_filter(self.context, self.interception.interception_is_keyboard, InterceptionFilterKeyState.INTERCEPTION_FILTER_KEY_ALL); 555 | self.interception.interception_set_filter(self.context, self.interception.interception_is_mouse, InterceptionFilterMouseState.INTERCEPTION_FILTER_MOUSE_ALL); 556 | 557 | # Store a default keyboard and a default mouse 558 | hardware_id = ctypes.c_byte * 512 559 | for i in range(10): 560 | current_dev = self.interception.INTERCEPTION_KEYBOARD(i) 561 | if (self.interception.interception_is_keyboard(current_dev)): 562 | size = self.interception.interception_get_hardware_id(self.context, current_dev, ctypes.byref(hardware_id()), 512); 563 | if (size != 0): 564 | self.default_keyboard_device = current_dev 565 | break 566 | for i in range(10): 567 | current_dev = self.interception.INTERCEPTION_MOUSE(i) 568 | if (self.interception.interception_is_mouse(current_dev)): 569 | size = self.interception.interception_get_hardware_id(self.context, current_dev, ctypes.byref(hardware_id()), 512); 570 | if (size != 0): 571 | self.default_mouse_device = current_dev 572 | break 573 | 574 | 575 | # Start threads. These will run the functions the user writes 576 | self.kb_thread = FunctionRunner(self.kb_queue) 577 | self.kb_thread.setDaemon(True) 578 | self.kb_thread.start() 579 | self.mouse_thread = FunctionRunner(self.mouse_queue) 580 | self.mouse_thread.setDaemon(True) 581 | self.mouse_thread.start() 582 | self.macro_thread = FunctionRunner(self.macro_queue) 583 | self.macro_thread.setDaemon(True) 584 | self.macro_thread.start() 585 | 586 | 587 | #reserve space for the stroke 588 | stroke = InterceptionStroke() 589 | 590 | while (self.running): 591 | device = self.interception.interception_wait(self.context) 592 | # print("#####DEVICE ID:"+str(device)) 593 | if (self.interception.interception_receive(self.context, device, ctypes.byref(stroke), 1) > 0): 594 | if (self.interception.interception_is_keyboard(device)): 595 | kb_event=ctypes.cast(stroke, ctypes.POINTER(InterceptionKeyStroke)).contents 596 | if (self.recording_macro & self.enable_kb_macro): 597 | self.last_macro.append((time.time(), copy.deepcopy(kb_event))) 598 | current_key = self.get_key_id(kb_event.code,kb_event.state) 599 | current_state = self.keyboard_state[current_key] #current state for the key 600 | self.keyboard_state[current_key] = kb_event.state 601 | if (kb_event.state & InterceptionKeyState.INTERCEPTION_KEY_UP): #up 602 | user_function = self.keyboard_handler_up[current_key] 603 | else:# down 604 | if (current_state == kb_event.state): 605 | user_function = self.keyboard_handler_hold[current_key] 606 | else: 607 | user_function = self.keyboard_handler_down[current_key] 608 | 609 | 610 | if (user_function): 611 | self.kb_queue.put(Task(self,user_function,copy.deepcopy(kb_event))) 612 | else: 613 | self.interception.interception_send(self.context, device, ctypes.byref(stroke), 1) 614 | 615 | elif (self.interception.interception_is_mouse(device)): 616 | mouse_event=ctypes.cast(stroke, ctypes.POINTER(InterceptionMouseStroke)).contents 617 | if (self.recording_macro & self.enable_mouse_macro): 618 | self.last_macro.append((time.time(), copy.deepcopy(mouse_event))) 619 | if (mouse_event.state != InterceptionMouseState.INTERCEPTION_MOUSE_MOVE): 620 | current_state_changed = self.__toggleMouseState(mouse_event) 621 | if (current_state_changed): 622 | user_function = self.mouse_handler[mouse_event.state] 623 | else: 624 | #TODO: implement something to make a fake on hold. Mouse clicks don't automatically resend events like keyboard keys do 625 | user_function = self.mouse_handler_hold[mouse_event.state] 626 | else: 627 | user_function = self.mouse_move_handler 628 | #print("Stroke state:" + str(hex(mouse_event.state))) 629 | #print("Stroke flags:" + str(hex(mouse_event.flags))) 630 | #print("Stroke information:" + str(hex(mouse_event.information))) 631 | #print("Stroke rolling:" + str(hex(mouse_event.rolling))) 632 | #print("Stroke x:" + str(hex(mouse_event.x))) 633 | #print("Stroke y:" + str(hex(mouse_event.y))) 634 | #print("position 1:" +str(win32gui.GetCursorPos())) 635 | if (user_function): 636 | self.mouse_queue.put(Task(self,user_function,copy.deepcopy(mouse_event))) 637 | else: 638 | self.interception.interception_send(self.context, device, ctypes.byref(stroke), 1) 639 | if self.loopingCall != None: 640 | self.loopingCall(self) 641 | self.macro_queue.join() 642 | self.kb_queue.join() 643 | self.mouse_queue.join() 644 | self.interception.interception_destroy_context(self.context) 645 | 646 | def __toggleMouseState(self, mouse_event): 647 | """ 648 | applies the mouse state change 649 | returns False if no changes were made 650 | """ 651 | BUTTON1=1 652 | BUTTON2=2 653 | BUTTON3=3 654 | BUTTON4=4 655 | BUTTON5=5 656 | WHEEL=6 657 | HWHEEL=7 658 | newState = mouse_event.state 659 | if ((newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_DOWN) | (newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_UP)): 660 | return self.__updateButtonState(BUTTON1,newState) 661 | elif ((newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_DOWN) | (newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_UP)): 662 | return self.__updateButtonState(BUTTON2,newState) 663 | elif ((newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_DOWN) | (newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_UP)): 664 | return self.__updateButtonState(BUTTON3,newState) 665 | elif ((newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_DOWN) | (newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_UP)): 666 | return self.__updateButtonState(BUTTON4,newState) 667 | elif ((newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_DOWN) | (newState == InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_UP)): 668 | return self.__updateButtonState(BUTTON5,newState) 669 | elif (newState == InterceptionMouseState.INTERCEPTION_MOUSE_WHEEL): 670 | return self.__updateButtonState(WHEEL,mouse_event.rolling) 671 | elif (newState == InterceptionMouseState.INTERCEPTION_MOUSE_HWHEEL): 672 | return self.__updateButtonState(HWHEEL,mouse_event.rolling) 673 | 674 | 675 | def __updateButtonState(self, button, newState): 676 | """ 677 | returns true if the button state has changed 678 | """ 679 | #Update button 1 if needed 680 | current_state = self.mouse_state[button] 681 | if (current_state==newState): 682 | return False 683 | else: 684 | self.mouse_state[button] = newState 685 | return True 686 | 687 | def isRunning(self): 688 | return self.running 689 | 690 | def stop(self): 691 | self.running = False 692 | 693 | def getKeyboardState(self, code, state): 694 | """ 695 | Return the key state for a given scancode + state mask 696 | """ 697 | return self.keyboard_state[self.get_key_id(code,state)] 698 | 699 | def getMouseState(self, code): 700 | return self.mouse_state[code] 701 | 702 | def registerExit(self, key, handler): 703 | self.exit_configured = True 704 | self.keyboard_handler_down[key.get_id()] = handler 705 | 706 | def registerForKeyDown(self, key, handler): 707 | self.keyboard_handler_down[key.get_id()] = handler 708 | 709 | def registerForKeyDownAndDisableHoldEvent(self, key, handler): 710 | self.keyboard_handler_down[key.get_id()] = handler 711 | self.keyboard_handler_hold[key.get_id()] = self.__null_handler 712 | 713 | def registerForKeyUp(self, key, handler): 714 | self.keyboard_handler_up[key.get_id()] = handler 715 | 716 | def registerForKeyHold(self, key, handler): 717 | self.keyboard_handler_hold[key.get_id()] = handler 718 | 719 | def registerForMouseButton(self, key, handler): 720 | self.mouse_handler[int(key)] = handler 721 | 722 | def registerForMouseButtonAndDisableHoldEvent(self, key, handler): 723 | self.mouse_handler[int(key)] = handler 724 | self.mouse_handler_hold[int(key)] = self.__null_handler 725 | 726 | def registerForMouseButtonHold(self, key, handler): 727 | self.keyboard_handler_hold[int(key)] = handler 728 | 729 | def registerForMouseMovement(self, handler): 730 | self.mouse_move_handler = handler 731 | 732 | def sendToDefaultMouse(self, stroke): 733 | self.interception.interception_send(self.context, self.default_mouse_device, ctypes.byref(stroke), 1) 734 | 735 | def sendToDefaultKeyboard(self, stroke): 736 | self.interception.interception_send(self.context, self.default_keyboard_device, ctypes.byref(stroke), 1) 737 | 738 | def sendToDevice(self, device, stroke): 739 | self.interception.interception_send(self.context, device, ctypes.byref(stroke), 1) 740 | 741 | def mouseMacroStartStop(self): 742 | """ 743 | start/stop recording a macro that only takes mouse events into account 744 | """ 745 | if (self.recording_macro): 746 | self.recording_macro = False 747 | else: 748 | self.enable_mouse_macro = True 749 | self.enable_kb_macro = False 750 | self.recording_macro = True 751 | def keyboardMacroStartStop(self): 752 | """ 753 | start/stop recording a macro that only saves keyboard events 754 | """ 755 | 756 | if (self.recording_macro): 757 | self.recording_macro = False 758 | else: 759 | self.enable_mouse_macro = False 760 | self.enable_kb_macro = True 761 | self.recording_macro = True 762 | 763 | def macroStartStop(self): 764 | """ 765 | start/stop recording a macro 766 | """ 767 | if (self.recording_macro): 768 | self.recording_macro = False 769 | else: 770 | self.enable_mouse_macro = True 771 | self.enable_kb_macro = True 772 | self.clearLastRecordedMacro() #clear old macro (if any) 773 | self.recording_macro = True 774 | 775 | def fireLastRecordedMacro(self): 776 | self.recording_macro = False 777 | self.macro_queue.put(Task(self,self.runMacro,self.last_macro)) 778 | 779 | def clearLastRecordedMacro(self): 780 | self.last_macro = [] 781 | 782 | def __getMouseFlagsString(self, event): 783 | flags = event.flags 784 | 785 | if (flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE): 786 | flags_string = "InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE" 787 | else: 788 | flags_string = "InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_RELATIVE" 789 | if (flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_VIRTUAL_DESKTOP): 790 | flags_string += "& InterceptionMouseFlag.INTERCEPTION_MOUSE_VIRTUAL_DESKTOP" 791 | if (flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_ATTRIBUTES_CHANGED): 792 | flags_string += "& InterceptionMouseFlag.INTERCEPTION_MOUSE_ATTRIBUTES_CHANGED" 793 | if (flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_NOCOALESCE): 794 | flags_string += "& InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_NOCOALESCE" 795 | if (flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_TERMSRV_SRC_SHADOW): 796 | flags_string += "& InterceptionMouseFlag.INTERCEPTION_MOUSE_TERMSRV_SRC_SHADOW" 797 | 798 | return flags_string 799 | 800 | def __getMouseStateString(self, event): 801 | return { 802 | 0x000 : "InterceptionMouseState.INTERCEPTION_MOUSE_MOVE", 803 | 0x001 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_DOWN", 804 | 0x002 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_UP", 805 | 0x004 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_DOWN", 806 | 0x008 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_UP", 807 | 0x010 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_DOWN", 808 | 0x020 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_UP", 809 | 0x040 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_DOWN", 810 | 0x080 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_UP", 811 | 0x100 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_DOWN", 812 | 0x200 : "InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_UP", 813 | 0x400 : "InterceptionMouseState.INTERCEPTION_MOUSE_WHEEL", 814 | 0x800 : "InterceptionMouseState.INTERCEPTION_MOUSE_HWHEEL", 815 | }[event.state] 816 | 817 | def saveLastRecordedMacro(self, filename,*args): 818 | openfile = open(filename, 'w') 819 | output_script_text = "from AutoHotPy import AutoHotPy\nfrom InterceptionWrapper import *\ndef exitAutoHotKey(autohotpy,event):\n autohotpy.stop()\ndef recorded_macro(autohotpy, event):\n" 820 | openfile.write(output_script_text) 821 | 822 | if (len(args) == 1): 823 | openfile.write(" autohotpy.moveMouseToPosition("+str(args[0][0])+","+str(args[0][1])+")\n") 824 | 825 | def getTimeDifference(old,new): 826 | if (old == 0): 827 | return 0 828 | return new-old 829 | 830 | def getEventKeyId(event): 831 | return self.get_key_id(event.code, event.state) 832 | 833 | last_time=0 834 | #removing invalid events that the macro accidentally stores 835 | #startkey UP is pressed as first char 836 | #startkey DOWN is pressed as last char 837 | macro_valid_elements = self.last_macro[1:len(self.last_macro)-1] 838 | for event in macro_valid_elements: 839 | sleep_time = getTimeDifference(last_time,event[0]) 840 | last_time = event[0] 841 | openfile.write(" autohotpy.sleep("+str(sleep_time)+")\n") 842 | if (isinstance(event[1],InterceptionMouseStroke)): 843 | openfile.write(" stroke = InterceptionMouseStroke()\n") 844 | openfile.write(" stroke.state = "+self.__getMouseStateString(event[1])+"\n") 845 | openfile.write(" stroke.flags = "+self.__getMouseFlagsString(event[1])+"\n") 846 | openfile.write(" stroke.rolling = "+str(event[1].rolling)+"\n") 847 | openfile.write(" stroke.x = "+str(event[1].x)+"\n") 848 | openfile.write(" stroke.y = "+str(event[1].y)+"\n") 849 | openfile.write(" stroke.information = "+str(event[1].information)+"\n") 850 | openfile.write(" autohotpy.sendToDefaultMouse(stroke)\n") 851 | elif(isinstance(event[1],InterceptionKeyStroke)): 852 | keyid =getEventKeyId(event[1]) 853 | if (keyid != None): 854 | key = self.keys[keyid] 855 | keyname = str(key) 856 | 857 | if (event[1].state & InterceptionKeyState.INTERCEPTION_KEY_UP): 858 | openfile.write(" autohotpy."+keyname+".up()\n") 859 | else: 860 | openfile.write(" autohotpy."+keyname+".down()\n") 861 | else: 862 | code = event[1].code 863 | state = event[1].state 864 | openfile.write(" stroke = InterceptionMouseStroke()\n") 865 | openfile.write(" stroke.code = "+str(code)+"\n") 866 | openfile.write(" stroke.state = "+str(state)+"\n") 867 | openfile.write(" stroke.information = "+str(event[1].information)+"\n") 868 | openfile.write(" autohotpy.sendToDefaultKeyboard(stroke)\n") 869 | openfile.write("if __name__==\"__main__\":\n auto = AutoHotPy()\n auto.registerExit(auto.ESC,exitAutoHotKey)\n auto.registerForKeyDown(auto.F1,recorded_macro)\n auto.start()\n") 870 | openfile.close() 871 | 872 | 873 | def isRecording(self): 874 | return self.recording_macro 875 | 876 | def getMousePosition(self): 877 | #x, y = win32api.GetCursorPos() 878 | res = Point() 879 | self.user32.GetCursorPos(ctypes.byref(res)) 880 | return (res.x,res.y) 881 | 882 | def moveMouseToPosition(self, x, y): 883 | width_constant = 65535.0/float(self.user32.GetSystemMetrics(0)) 884 | height_constant = 65535.0/float(self.user32.GetSystemMetrics (1)) 885 | # move mouse to the specified position 886 | stroke = InterceptionMouseStroke() 887 | stroke.state = InterceptionMouseState.INTERCEPTION_MOUSE_MOVE 888 | stroke.flags = InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE 889 | stroke.x = int(float(x)*width_constant) 890 | stroke.y = int(float(y)*height_constant) 891 | self.sendToDefaultMouse(stroke) 892 | 893 | def run(self, macro, trigger_event): 894 | """ 895 | manually send a macro to be run 896 | """ 897 | if (isinstance(trigger_event,InterceptionMouseStroke)): 898 | self.mouse_queue.put(Task(self, macro, trigger_event)) 899 | elif(isinstance(trigger_event,InterceptionKeyStroke)): 900 | self.kb_queue.put(Task(self, macro, trigger_event)) 901 | 902 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /COPYING.LESSER: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /Example1-GameCombo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | #The example starts here 22 | from AutoHotPy import AutoHotPy # we need to tell python that we are going to use the library 23 | 24 | 25 | # The following function is called when you press ESC. 26 | #autohotpy is the instance that controlls the library, you should do everything through it. 27 | def exitAutoHotKey(autohotpy,event): 28 | """ 29 | exit the program when you press ESC 30 | """ 31 | autohotpy.stop() #makes the program finish successfully. Thisis the right way to stop it 32 | 33 | def superCombo(autohotpy,event): 34 | """ 35 | This function is called when you press "A" key. 36 | It executes the combo: A -> S -> move left -> move up -> A -> S 37 | """ 38 | autohotpy.A.press() # press() method simulates a key press by sending first the key down, and later the key up events 39 | autohotpy.S.press() 40 | autohotpy.LEFT_ARROW.press() 41 | autohotpy.UP_ARROW.press() 42 | autohotpy.A.press() 43 | autohotpy.S.press() 44 | 45 | 46 | # THIS IS WERE THE PROGRAM STARTS EXECUTING!!!!!!!! 47 | if __name__=="__main__": 48 | auto = AutoHotPy() #Initialize the library 49 | auto.registerExit(auto.ESC, exitAutoHotKey) # Registering an end key is mandatory to be able to stop the program gracefully 50 | auto.registerForKeyDown(auto.A,superCombo) # This method lets you say: "when I press A in the keyboard, then execute "superCombo" 51 | auto.start() #Now that everything is registered we should start runnin the program 52 | -------------------------------------------------------------------------------- /Example10-Macros6 - Record keyboard only.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from AutoHotPy import AutoHotPy 22 | 23 | def exitAutoHotKey(autohotpy,event): 24 | """ 25 | exit the program when you press ESC 26 | """ 27 | autohotpy.stop() 28 | 29 | def startStopMacro(autohotpy,event): 30 | autohotpy.keyboardMacroStartStop() #record keyboard only 31 | 32 | 33 | def fireMacro(autohotpy,event): 34 | autohotpy.fireLastRecordedMacro() 35 | 36 | def clearMacro(autohotpy,event): 37 | autohotpy.clearLastRecordedMacro() 38 | 39 | if __name__=="__main__": 40 | auto = AutoHotPy() 41 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 42 | 43 | auto.registerForKeyDown(auto.F1,startStopMacro) 44 | auto.registerForKeyDown(auto.F2,fireMacro) 45 | auto.registerForKeyDown(auto.F3,clearMacro) 46 | 47 | auto.start() 48 | -------------------------------------------------------------------------------- /Example11-Joystick to ALT F4.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: Emilio Moretti 3 | Copyright 2014 Emilio Moretti 4 | This program is distributed under the terms of the GNU Lesser General Public License. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | """ 19 | ####################################### 20 | # Press Alt+F4 after pressing a joystick button combination 21 | ####################################### 22 | import pygame 23 | from pygame.locals import * 24 | 25 | # do something when the following buttons are pressed: 26 | # joystick 0: button 3 + joystick 0: button 9 + joystick 1: button 2 27 | PRESSED_BUTTONS = [(0,3),(0,9),(1,2)] 28 | 29 | 30 | class App: 31 | def autoHotPyMacro(self,autoHotPyInstance): 32 | autoHotPyInstance.LEFT_ALT.down() #release alt 33 | autoHotPyInstance.sleep() #don't forget to sleep when you manually send a "down" state 34 | autoHotPyInstance.F4.down() 35 | autoHotPyInstance.sleep() 36 | autoHotPyInstance.LEFT_ALT.up() 37 | autoHotPyInstance.F4.up() 38 | 39 | def __init__(self): 40 | pygame.init() 41 | 42 | # Set up the joystick 43 | pygame.joystick.init() 44 | 45 | self.my_joysticks = {} 46 | 47 | for joy,button in PRESSED_BUTTONS: 48 | self.my_joysticks[joy] = pygame.joystick.Joystick(joy) 49 | self.my_joysticks[joy].init() 50 | 51 | 52 | # A couple of joystick functions... 53 | def check_axis(self, joystick, p_axis): 54 | if (joystick in self.my_joysticks.keys()): 55 | if (p_axis < self.my_joysticks[joystick].get_numaxes()): 56 | return self.my_joysticks[joystick].get_axis(p_axis) 57 | 58 | return 0 59 | 60 | def check_button(self, joystick, p_button): 61 | if (joystick in self.my_joysticks.keys()): 62 | if (p_button < self.my_joysticks[joystick].get_numbuttons()): 63 | return self.my_joysticks[joystick].get_button(p_button) 64 | 65 | return False 66 | 67 | def check_hat(self, joystick, p_hat): 68 | if (joystick in self.my_joysticks.keys()): 69 | if (p_hat < self.my_joysticks[joystick].get_numhats()): 70 | return self.my_joysticks[joystick].get_hat(p_hat) 71 | 72 | return (0, 0) 73 | 74 | def loopingCall(self,autohotpy): 75 | self.g_keys = pygame.event.get() 76 | for event in self.g_keys: 77 | if (event.type == QUIT): 78 | self.quit() 79 | return 80 | all_pressed = True 81 | for joystick,button in PRESSED_BUTTONS: 82 | if not(self.check_button(joystick,button)): 83 | all_pressed = False 84 | break 85 | if all_pressed: 86 | self.autoHotPyMacro(autohotpy) 87 | 88 | def quit(self): 89 | #pygame.display.quit() 90 | exit(0) 91 | 92 | if __name__=="__main__": 93 | auto = AutoHotPy() #Initialize the library 94 | auto.registerExit(auto.ESC, exitAutoHotKey) # Registering an end key is mandatory to be able to stop the program gracefully 95 | app = App() 96 | auto.loopingCall = app.loopingCall 97 | auto.start() #Now that everything is registered we should start runnin the program 98 | 99 | 100 | -------------------------------------------------------------------------------- /Example2-MultipleKeys.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | from AutoHotPy import AutoHotPy 21 | 22 | def exitAutoHotKey(autohotpy,event): 23 | """ 24 | exit the program when you press Ctrl + Alt + F10 25 | """ 26 | if (autohotpy.LEFT_CTRL.isPressed() & autohotpy.LEFT_ALT.isPressed()): #check if ctrl and alt are also pressed 27 | autohotpy.stop() 28 | else:#if ctrl +al is not pressed, then it's a normal F10 keypress. send it as is 29 | autohotpy.sendToDefaultKeyboard(event) 30 | 31 | def openTaskManager(autohotpy,event): 32 | """ 33 | This function is called when you press DELETE key 34 | """ 35 | if (autohotpy.LEFT_CTRL.isPressed() & autohotpy.LEFT_ALT.isPressed()): #check if ctrl and alt are also pressed 36 | autohotpy.LEFT_ALT.up() #release alt 37 | autohotpy.sleep() #don't forget to sleep when you manually send a "down" state 38 | autohotpy.LEFT_SHIFT.down() 39 | autohotpy.sleep() 40 | autohotpy.ESC.down() 41 | autohotpy.sleep() 42 | autohotpy.LEFT_SHIFT.up() 43 | autohotpy.ESC.up() 44 | else: #if ctrl +al is not pressed, then it's a normal Del keypress. send it as is 45 | autohotpy.sendToDefaultKeyboard(event) 46 | 47 | if __name__=="__main__": 48 | auto = AutoHotPy() 49 | auto.registerExit(auto.F10,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 50 | 51 | # In win7 the task manager is launched when you press Ctrl + Shift + ESC 52 | # I don't like that. Lets call the task manager when you press Ctrl + Alt + Supr 53 | auto.registerForKeyDown(auto.DELETE,openTaskManager) 54 | auto.start() 55 | -------------------------------------------------------------------------------- /Example3-MouseButtons.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | #WARNING: handling mouse events is harder than keyboard events. 22 | # You have to do most things manually 23 | from AutoHotPy import AutoHotPy 24 | from InterceptionWrapper import InterceptionMouseState,InterceptionMouseStroke 25 | 26 | 27 | def exitAutoHotKey(autohotpy,event): 28 | """ 29 | exit the program when you press ESC 30 | """ 31 | autohotpy.stop() 32 | 33 | def rightButton(autohotpy,event): 34 | """ 35 | This function simulates a right click 36 | """ 37 | stroke = InterceptionMouseStroke() # I highly suggest you to open InterceptionWrapper to read which attributes this class has 38 | 39 | #To simulate a mouse click we manually have to press down, and release the buttons we want. 40 | stroke.state = InterceptionMouseState.INTERCEPTION_MOUSE_RIGHT_BUTTON_DOWN 41 | autohotpy.sendToDefaultMouse(stroke) 42 | stroke.state = InterceptionMouseState.INTERCEPTION_MOUSE_RIGHT_BUTTON_UP 43 | autohotpy.sendToDefaultMouse(stroke) 44 | 45 | def leftButton(autohotpy,event): 46 | """ 47 | This function simulates a left click 48 | """ 49 | stroke = InterceptionMouseStroke() 50 | stroke.state = InterceptionMouseState.INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN 51 | autohotpy.sendToDefaultMouse(stroke) 52 | stroke.state = InterceptionMouseState.INTERCEPTION_MOUSE_LEFT_BUTTON_UP 53 | autohotpy.sendToDefaultMouse(stroke) 54 | 55 | 56 | if __name__=="__main__": 57 | auto = AutoHotPy() 58 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 59 | 60 | # lets switch right and left mouse buttons! 61 | auto.registerForMouseButton(InterceptionMouseState.INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN,rightButton) 62 | auto.registerForMouseButton(InterceptionMouseState.INTERCEPTION_MOUSE_RIGHT_BUTTON_DOWN,leftButton) 63 | auto.start() 64 | -------------------------------------------------------------------------------- /Example4-MouseMovement.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | #WARNING: handling mouse events is harder than keyboard events. 22 | # You have to do most things manually 23 | from AutoHotPy import AutoHotPy 24 | from InterceptionWrapper import InterceptionMouseState,InterceptionMouseStroke,InterceptionMouseFlag 25 | 26 | 27 | def exitAutoHotKey(autohotpy,event): 28 | """ 29 | exit the program when you press ESC 30 | """ 31 | autohotpy.stop() 32 | 33 | def moveHandler(autohotpy,event): 34 | """ 35 | This function inverts mouse axis! 36 | """ 37 | if not(event.flags & InterceptionMouseFlag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE): 38 | event.x *= -1 39 | event.y *= -1 40 | autohotpy.sendToDefaultMouse(event) 41 | 42 | 43 | if __name__=="__main__": 44 | auto = AutoHotPy() 45 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 46 | 47 | # lets switch right and left mouse buttons! 48 | auto.registerForMouseMovement(moveHandler) 49 | auto.start() 50 | -------------------------------------------------------------------------------- /Example5-Macros.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | #WARNING: handling mouse events is harder than keyboard events. 22 | # You have to do most things manually 23 | from AutoHotPy import AutoHotPy 24 | from InterceptionWrapper import InterceptionMouseState,InterceptionMouseStroke,InterceptionMouseFlag 25 | 26 | 27 | def exitAutoHotKey(autohotpy,event): 28 | """ 29 | exit the program when you press ESC 30 | """ 31 | autohotpy.stop() 32 | 33 | def startStopMacro(autohotpy,event): 34 | autohotpy.macroStartStop() 35 | 36 | def fireMacro(autohotpy,event): 37 | autohotpy.fireLastRecordedMacro() 38 | 39 | def clearMacro(autohotpy,event): 40 | autohotpy.clearLastRecordedMacro() 41 | 42 | if __name__=="__main__": 43 | auto = AutoHotPy() 44 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 45 | 46 | auto.registerForKeyDown(auto.F1,startStopMacro) 47 | auto.registerForKeyDown(auto.F2,fireMacro) 48 | auto.registerForKeyDown(auto.F3,clearMacro) 49 | 50 | auto.start() 51 | -------------------------------------------------------------------------------- /Example6-Macros2 - Gaming macros.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from AutoHotPy import AutoHotPy 22 | 23 | initial_position = (0,0) 24 | 25 | def exitAutoHotKey(autohotpy,event): 26 | """ 27 | exit the program when you press ESC 28 | """ 29 | autohotpy.stop() 30 | 31 | def startStopMacro(autohotpy,event): 32 | global initial_position 33 | if not autohotpy.isRecording(): 34 | initial_position = autohotpy.getMousePosition() 35 | autohotpy.macroStartStop() 36 | 37 | 38 | def fireMacro(autohotpy,event): 39 | global initial_position 40 | autohotpy.moveMouseToPosition(initial_position[0],initial_position[1]) 41 | autohotpy.fireLastRecordedMacro() 42 | 43 | def clearMacro(autohotpy,event): 44 | autohotpy.clearLastRecordedMacro() 45 | 46 | if __name__=="__main__": 47 | auto = AutoHotPy() 48 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 49 | 50 | auto.registerForKeyDown(auto.F1,startStopMacro) 51 | auto.registerForKeyDown(auto.F2,fireMacro) 52 | auto.registerForKeyDown(auto.F3,clearMacro) 53 | 54 | auto.start() 55 | -------------------------------------------------------------------------------- /Example7-Macros3 - Saving macro to file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from AutoHotPy import AutoHotPy 22 | from InterceptionWrapper import * 23 | 24 | mouse_initial_position = (0,0) 25 | save_file = "./recorded_macro.py" 26 | 27 | def exitAutoHotKey(autohotpy,event): 28 | """ 29 | exit the program when you press ESC 30 | """ 31 | autohotpy.stop() 32 | 33 | def startStopMacro(autohotpy,event): 34 | global mouse_initial_position 35 | if not autohotpy.isRecording(): 36 | mouse_initial_position = autohotpy.getMousePosition() 37 | autohotpy.macroStartStop() 38 | 39 | 40 | def fireMacro(autohotpy,event): 41 | global mouse_initial_position 42 | autohotpy.moveMouseToPosition(mouse_initial_position[0],mouse_initial_position[1]) 43 | autohotpy.fireLastRecordedMacro() 44 | 45 | def clearMacro(autohotpy,event): 46 | autohotpy.clearLastRecordedMacro() 47 | 48 | def saveMacro(autohotpy,event): 49 | global mouse_initial_position 50 | autohotpy.saveLastRecordedMacro(save_file,mouse_initial_position) 51 | 52 | 53 | if __name__=="__main__": 54 | auto = AutoHotPy() 55 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 56 | 57 | auto.registerForKeyDown(auto.F1,startStopMacro) 58 | auto.registerForKeyDown(auto.F2,fireMacro) 59 | auto.registerForKeyDown(auto.F3,saveMacro) 60 | auto.registerForKeyDown(auto.F10,clearMacro) 61 | 62 | auto.start() 63 | -------------------------------------------------------------------------------- /Example8-Macros4 - Auto-repeating macros.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from AutoHotPy import AutoHotPy 22 | from InterceptionWrapper import * 23 | 24 | repeat_always = False 25 | 26 | def exitAutoHotKey(autohotpy,event): 27 | """ 28 | exit the program when you press ESC 29 | """ 30 | autohotpy.stop() 31 | 32 | def alwaysLoopMacro(autohotpy,event): 33 | global repeat_always 34 | autohotpy.A.press() 35 | autohotpy.B.press() 36 | autohotpy.C.press() 37 | 38 | #now that we are finished, let's check if we should loop 39 | # If repeat_always= true, then we tell autohotpy to run loopMacro again 40 | if repeat_always: 41 | autohotpy.run(alwaysLoopMacro, event) 42 | 43 | def enableDisableLoopMacro(autohotpy, event): 44 | global repeat_always 45 | 46 | if repeat_always: 47 | repeat_always = False 48 | else: 49 | # let's enable it, and then we call it for the first time, so it starts running as soon as possible 50 | repeat_always = True 51 | alwaysLoopMacro(autohotpy, event) 52 | 53 | 54 | if __name__=="__main__": 55 | auto = AutoHotPy() 56 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 57 | 58 | auto.registerForKeyDown(auto.F1,enableDisableLoopMacro) 59 | 60 | auto.start() 61 | -------------------------------------------------------------------------------- /Example9-Macros5 - Record mouse only.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from AutoHotPy import AutoHotPy 22 | 23 | initial_position = (0,0) 24 | 25 | def exitAutoHotKey(autohotpy,event): 26 | """ 27 | exit the program when you press ESC 28 | """ 29 | autohotpy.stop() 30 | 31 | def startStopMacro(autohotpy,event): 32 | global initial_position 33 | if not autohotpy.isRecording(): 34 | initial_position = autohotpy.getMousePosition() 35 | autohotpy.mouseMacroStartStop() #record mouse only 36 | 37 | 38 | def fireMacro(autohotpy,event): 39 | global initial_position 40 | autohotpy.moveMouseToPosition(initial_position[0],initial_position[1]) 41 | autohotpy.fireLastRecordedMacro() 42 | 43 | def clearMacro(autohotpy,event): 44 | autohotpy.clearLastRecordedMacro() 45 | 46 | if __name__=="__main__": 47 | auto = AutoHotPy() 48 | auto.registerExit(auto.ESC,exitAutoHotKey) # Registering an end key is mandatory to be able tos top the program gracefully 49 | 50 | auto.registerForKeyDown(auto.F1,startStopMacro) 51 | auto.registerForKeyDown(auto.F2,fireMacro) 52 | auto.registerForKeyDown(auto.F3,clearMacro) 53 | 54 | auto.start() 55 | -------------------------------------------------------------------------------- /InterceptionWrapper.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: Emilio Moretti 4 | Copyright 2013 Emilio Moretti 5 | This program is distributed under the terms of the GNU Lesser General Public License. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | # ctypes to work with interception .dll 21 | import ctypes 22 | 23 | class InterceptionKeyState(object): 24 | INTERCEPTION_KEY_DOWN = 0x00 25 | INTERCEPTION_KEY_UP = 0x01 26 | INTERCEPTION_KEY_E0 = 0x02 27 | INTERCEPTION_KEY_E1 = 0x04 28 | INTERCEPTION_KEY_TERMSRV_SET_LED = 0x08 29 | INTERCEPTION_KEY_TERMSRV_SHADOW = 0x10 30 | INTERCEPTION_KEY_TERMSRV_VKPACKET = 0x20 31 | 32 | class InterceptionFilterKeyState(object): 33 | INTERCEPTION_FILTER_KEY_NONE = 0x0000 34 | INTERCEPTION_FILTER_KEY_ALL = 0xFFFF 35 | INTERCEPTION_FILTER_KEY_DOWN = InterceptionKeyState.INTERCEPTION_KEY_UP 36 | INTERCEPTION_FILTER_KEY_UP = InterceptionKeyState.INTERCEPTION_KEY_UP << 1 37 | INTERCEPTION_FILTER_KEY_E0 = InterceptionKeyState.INTERCEPTION_KEY_E0 << 1 38 | INTERCEPTION_FILTER_KEY_E1 = InterceptionKeyState.INTERCEPTION_KEY_E1 << 1 39 | INTERCEPTION_FILTER_KEY_TERMSRV_SET_LED = InterceptionKeyState.INTERCEPTION_KEY_TERMSRV_SET_LED << 1 40 | INTERCEPTION_FILTER_KEY_TERMSRV_SHADOW = InterceptionKeyState.INTERCEPTION_KEY_TERMSRV_SHADOW << 1 41 | INTERCEPTION_FILTER_KEY_TERMSRV_VKPACKET = InterceptionKeyState.INTERCEPTION_KEY_TERMSRV_VKPACKET << 1 42 | 43 | class InterceptionMouseState(object): 44 | INTERCEPTION_MOUSE_MOVE = 0x000 45 | INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN = 0x001 46 | INTERCEPTION_MOUSE_LEFT_BUTTON_UP = 0x002 47 | INTERCEPTION_MOUSE_RIGHT_BUTTON_DOWN = 0x004 48 | INTERCEPTION_MOUSE_RIGHT_BUTTON_UP = 0x008 49 | INTERCEPTION_MOUSE_MIDDLE_BUTTON_DOWN = 0x010 50 | INTERCEPTION_MOUSE_MIDDLE_BUTTON_UP = 0x020 51 | INTERCEPTION_MOUSE_BUTTON_1_DOWN = INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN 52 | INTERCEPTION_MOUSE_BUTTON_1_UP = INTERCEPTION_MOUSE_LEFT_BUTTON_UP 53 | INTERCEPTION_MOUSE_BUTTON_2_DOWN = INTERCEPTION_MOUSE_RIGHT_BUTTON_DOWN 54 | INTERCEPTION_MOUSE_BUTTON_2_UP = INTERCEPTION_MOUSE_RIGHT_BUTTON_UP 55 | INTERCEPTION_MOUSE_BUTTON_3_DOWN = INTERCEPTION_MOUSE_MIDDLE_BUTTON_DOWN 56 | INTERCEPTION_MOUSE_BUTTON_3_UP = INTERCEPTION_MOUSE_MIDDLE_BUTTON_UP 57 | INTERCEPTION_MOUSE_BUTTON_4_DOWN = 0x040 58 | INTERCEPTION_MOUSE_BUTTON_4_UP = 0x080 59 | INTERCEPTION_MOUSE_BUTTON_5_DOWN = 0x100 60 | INTERCEPTION_MOUSE_BUTTON_5_UP = 0x200 61 | INTERCEPTION_MOUSE_WHEEL = 0x400 62 | INTERCEPTION_MOUSE_HWHEEL = 0x800 63 | 64 | class InterceptionFilterMouseState(object): 65 | INTERCEPTION_FILTER_MOUSE_NONE = 0x0000 66 | INTERCEPTION_FILTER_MOUSE_ALL = 0xFFFF 67 | INTERCEPTION_FILTER_MOUSE_LEFT_BUTTON_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN 68 | INTERCEPTION_FILTER_MOUSE_LEFT_BUTTON_UP = InterceptionMouseState.INTERCEPTION_MOUSE_LEFT_BUTTON_UP 69 | INTERCEPTION_FILTER_MOUSE_RIGHT_BUTTON_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_RIGHT_BUTTON_DOWN 70 | INTERCEPTION_FILTER_MOUSE_RIGHT_BUTTON_UP = InterceptionMouseState.INTERCEPTION_MOUSE_RIGHT_BUTTON_UP 71 | INTERCEPTION_FILTER_MOUSE_MIDDLE_BUTTON_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_MIDDLE_BUTTON_DOWN 72 | INTERCEPTION_FILTER_MOUSE_MIDDLE_BUTTON_UP = InterceptionMouseState.INTERCEPTION_MOUSE_MIDDLE_BUTTON_UP 73 | INTERCEPTION_FILTER_MOUSE_BUTTON_1_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_DOWN 74 | INTERCEPTION_FILTER_MOUSE_BUTTON_1_UP = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_1_UP 75 | INTERCEPTION_FILTER_MOUSE_BUTTON_2_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_DOWN 76 | INTERCEPTION_FILTER_MOUSE_BUTTON_2_UP = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_2_UP 77 | INTERCEPTION_FILTER_MOUSE_BUTTON_3_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_DOWN 78 | INTERCEPTION_FILTER_MOUSE_BUTTON_3_UP = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_3_UP 79 | INTERCEPTION_FILTER_MOUSE_BUTTON_4_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_DOWN 80 | INTERCEPTION_FILTER_MOUSE_BUTTON_4_UP = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_4_UP 81 | INTERCEPTION_FILTER_MOUSE_BUTTON_5_DOWN = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_DOWN 82 | INTERCEPTION_FILTER_MOUSE_BUTTON_5_UP = InterceptionMouseState.INTERCEPTION_MOUSE_BUTTON_5_UP 83 | INTERCEPTION_FILTER_MOUSE_WHEEL = InterceptionMouseState.INTERCEPTION_MOUSE_WHEEL 84 | INTERCEPTION_FILTER_MOUSE_HWHEEL = InterceptionMouseState.INTERCEPTION_MOUSE_HWHEEL 85 | INTERCEPTION_FILTER_MOUSE_MOVE = 0x1000 86 | 87 | class InterceptionMouseFlag(object): 88 | """ 89 | If INTERCEPTION_MOUSE_MOVE_ABSOLUTE value is specified, dx and dy contain 90 | normalized absolute coordinates between 0 and 65,535. 91 | The event procedure maps these coordinates onto the display surface. 92 | Coordinate (0,0) maps onto the upper-left corner of the display surface; 93 | coordinate (65535,65535) maps onto the lower-right corner. 94 | In a multimonitor system, the coordinates map to the primary monitor. 95 | http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx 96 | """ 97 | INTERCEPTION_MOUSE_MOVE_RELATIVE = 0x000 98 | INTERCEPTION_MOUSE_MOVE_ABSOLUTE = 0x001 99 | INTERCEPTION_MOUSE_VIRTUAL_DESKTOP = 0x002 100 | INTERCEPTION_MOUSE_ATTRIBUTES_CHANGED = 0x004 101 | INTERCEPTION_MOUSE_MOVE_NOCOALESCE = 0x008 102 | INTERCEPTION_MOUSE_TERMSRV_SRC_SHADOW = 0x100 103 | 104 | class InterceptionMouseStroke(ctypes.Structure): 105 | _fields_ = [("state", ctypes.c_ushort), 106 | ("flags", ctypes.c_ushort), 107 | ("rolling", ctypes.c_short), 108 | ("x", ctypes.c_int), 109 | ("y", ctypes.c_int), 110 | ("information", ctypes.c_uint)] 111 | 112 | 113 | class InterceptionKeyStroke(ctypes.Structure): 114 | _fields_ = [("code", ctypes.c_ushort), 115 | ("state", ctypes.c_ushort), 116 | ("information", ctypes.c_uint)] 117 | 118 | class Point(ctypes.Structure): 119 | _fields_ = [("x", ctypes.c_long), 120 | ("y", ctypes.c_long)] 121 | 122 | #typedef char InterceptionStroke[sizeof(InterceptionMouseStroke)]; 123 | InterceptionStroke = InterceptionMouseStroke * 1 124 | 125 | #typedef void *InterceptionContext; 126 | InterceptionContext_p = ctypes.c_void_p 127 | 128 | #typedef int InterceptionDevice; 129 | InterceptionDevice = ctypes.c_int 130 | 131 | #typedef int InterceptionPrecedence; 132 | InterceptionPrecedence = ctypes.c_int 133 | 134 | #typedef unsigned short InterceptionFilter; 135 | InterceptionFilter = ctypes.c_uint 136 | 137 | 138 | 139 | 140 | class InterceptionWrapper(object): 141 | INTERCEPTION_MAX_KEYBOARD = 10 142 | INTERCEPTION_MAX_MOUSE = 10 143 | INTERCEPTION_MAX_DEVICE = ((INTERCEPTION_MAX_KEYBOARD) + (INTERCEPTION_MAX_MOUSE)) 144 | 145 | def INTERCEPTION_KEYBOARD(self, index): 146 | return ((index) + 1) 147 | 148 | def INTERCEPTION_MOUSE(self, index): 149 | return ((self.INTERCEPTION_MAX_KEYBOARD) + (index) + 1) 150 | 151 | def __interception_is_invalid(self, device): 152 | """ 153 | int ITERCEPTION_API interception_is_invalid(InterceptionDevice device); 154 | """ 155 | return self.interceptionDll.interception_is_invalid(device) 156 | 157 | def __interception_is_keyboard(self, device): 158 | """ 159 | int ITERCEPTION_API interception_is_keyboard(InterceptionDevice device); 160 | """ 161 | return self.interceptionDll.interception_is_keyboard(device) 162 | 163 | def __interception_is_mouse(self, device): 164 | """ 165 | int ITERCEPTION_API interception_is_mouse(InterceptionDevice device); 166 | """ 167 | return self.interceptionDll.interception_is_mouse(device) 168 | 169 | def __init__(self): 170 | # Load DLL into memory. 171 | self.interceptionDll = ctypes.WinDLL ("./interception.dll") 172 | 173 | # Setup return types 174 | self.interceptionDll.interception_create_context.restype = InterceptionContext_p 175 | self.interceptionDll.interception_get_filter.restype = InterceptionFilter 176 | self.interceptionDll.interception_get_precedence.restype = InterceptionPrecedence 177 | self.interceptionDll.interception_wait.restype = InterceptionDevice 178 | self.interceptionDll.interception_wait_with_timeout.restype = InterceptionDevice 179 | self.interceptionDll.interception_is_invalid.restype = ctypes.c_int 180 | self.interceptionDll.interception_is_keyboard.restype = ctypes.c_int 181 | self.interceptionDll.interception_is_mouse.restype = ctypes.c_int 182 | self.interceptionDll.interception_send.restype = ctypes.c_int 183 | self.interceptionDll.interception_receive.restype = ctypes.c_int 184 | self.interceptionDll.interception_get_hardware_id.restype = ctypes.c_uint 185 | 186 | 187 | #Setup callback functions (that actually call the dll again) 188 | funct_type = ctypes.WINFUNCTYPE(ctypes.c_int,InterceptionDevice) 189 | self.interception_is_invalid = funct_type(self.__interception_is_invalid) 190 | self.interception_is_keyboard = funct_type(self.__interception_is_keyboard) 191 | self.interception_is_mouse = funct_type(self.__interception_is_mouse) 192 | 193 | 194 | # Setup argument info for functions requiring pointer to InterceptionContext 195 | self.interceptionDll.interception_destroy_context.argtypes = [InterceptionContext_p] 196 | self.interceptionDll.interception_set_filter.argtypes = [InterceptionContext_p, 197 | funct_type, 198 | InterceptionFilter] 199 | self.interceptionDll.interception_get_filter.argtypes = [InterceptionContext_p, 200 | InterceptionDevice] 201 | self.interceptionDll.interception_get_precedence.argtypes = [InterceptionContext_p, 202 | InterceptionDevice] 203 | self.interceptionDll.interception_set_precedence.argtypes = [InterceptionContext_p, 204 | InterceptionDevice, 205 | InterceptionPrecedence] 206 | self.interceptionDll.interception_wait.argtypes = [InterceptionContext_p] 207 | self.interceptionDll.interception_wait_with_timeout.argtypes = [InterceptionContext_p] 208 | self.interceptionDll.interception_send.argtypes = [InterceptionContext_p, 209 | InterceptionDevice, 210 | ctypes.c_void_p, 211 | ctypes.c_uint] 212 | self.interceptionDll.interception_receive.argtypes = [InterceptionContext_p, 213 | InterceptionDevice, 214 | ctypes.c_void_p, 215 | ctypes.c_uint] 216 | self.interceptionDll.interception_get_hardware_id.argtypes = [InterceptionContext_p, 217 | InterceptionDevice, 218 | ctypes.c_void_p, 219 | ctypes.c_uint] 220 | 221 | 222 | def interception_create_context(self): 223 | """ 224 | InterceptionContext ITERCEPTION_API interception_create_context(void); 225 | """ 226 | return self.interceptionDll.interception_create_context() 227 | 228 | def interception_destroy_context(self, context): 229 | """ 230 | void ITERCEPTION_API interception_destroy_context(InterceptionContext context); 231 | """ 232 | return self.interceptionDll.interception_destroy_context(context) 233 | 234 | def interception_set_filter(self, context, predicate, filter1): 235 | """ 236 | void ITERCEPTION_API interception_set_filter(InterceptionContext context, InterceptionPredicate predicate, InterceptionFilter filter); 237 | """ 238 | return self.interceptionDll.interception_set_filter(context, predicate, filter1) 239 | 240 | def interception_get_filter(self, context, device): 241 | """ 242 | InterceptionFilter ITERCEPTION_API interception_get_filter(InterceptionContext context, InterceptionDevice device); 243 | """ 244 | return self.interceptionDll.interception_get_filter(context, device) 245 | 246 | def interception_get_precedence(self, context, device): 247 | """ 248 | InterceptionPrecedence ITERCEPTION_API interception_get_precedence(InterceptionContext context, InterceptionDevice device); 249 | """ 250 | return self.interceptionDll.interception_get_precedence(context, device) 251 | 252 | def interception_set_precedence(self, context, device, precedence): 253 | """ 254 | void ITERCEPTION_API interception_set_precedence(InterceptionContext context, InterceptionDevice device, InterceptionPrecedence precedence); 255 | """ 256 | return self.interceptionDll.interception_set_precedence(context, device, precedence) 257 | 258 | def interception_wait(self, context): 259 | """ 260 | InterceptionDevice ITERCEPTION_API interception_wait(InterceptionContext context); 261 | """ 262 | return self.interceptionDll.interception_wait(context) 263 | 264 | def interception_wait_with_timeout(self, context): 265 | """ 266 | InterceptionDevice ITERCEPTION_API interception_wait_with_timeout(InterceptionContext context, unsigned long milliseconds); 267 | """ 268 | return self.interceptionDll.interception_wait_with_timeout(context) 269 | 270 | def interception_send(self, context, device, stroke_p, nstroke): 271 | """ 272 | #int ITERCEPTION_API interception_send(InterceptionContext context, InterceptionDevice device, const InterceptionStroke *stroke, unsigned int nstroke); 273 | """ 274 | return self.interceptionDll.interception_send(context, device, stroke_p, nstroke) 275 | 276 | def interception_receive(self, context, device, stroke_p, nstroke): 277 | """ 278 | int ITERCEPTION_API interception_receive(InterceptionContext context, InterceptionDevice device, InterceptionStroke *stroke, unsigned int nstroke); 279 | """ 280 | return self.interceptionDll.interception_receive(context, device, stroke_p, nstroke) 281 | 282 | def interception_get_hardware_id(self, context, device, hardware_id_buffer_p, buffer_size): 283 | """ 284 | unsigned int ITERCEPTION_API interception_get_hardware_id(InterceptionContext context, InterceptionDevice device, void *hardware_id_buffer, unsigned int buffer_size); 285 | """ 286 | return self.interceptionDll.interception_get_hardware_id(context, device, hardware_id_buffer_p, buffer_size) 287 | 288 | 289 | #TODO: 290 | #the following typedef is not needed. it basically defines the function to send to set_filter (we do that manually) 291 | #typedef int (*InterceptionPredicate)(InterceptionDevice device); 292 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AutoHotPy 2 | ========= 3 | 4 | It started as an AutoHotKey replacement using Incerception driver, but now its a fully working automation tool. You can record activities to repeat them, or you can manually program them. 5 | 6 | # FAQ 7 | 8 | ## Why? just... why? 9 | AutoHotKey is great, but many games and programs don't work with it. And the ones that work have many counter-measures to stop it (because many script kiddies use it to cheat!). 10 | I'm against cheating in games, but I'm also against discrimination. Many players have different kinds of disabilities, and they need helping tools to play. 11 | I believe everyone deserves the right to choose which game, or program they want to use without limitations. 12 | 13 | ## How is it different? 14 | AutoHotPy is a scripting tool, just like AutoHotKey, but it uses Interception library (https://github.com/oblitum/Interception). 15 | The great thing is that Interception uses a very low level driver to capture keyboard and mouse events, which makes it perfect for games that have problems with AutoHotKey 16 | 17 | ## Why python? 18 | Because when you write AutoHotPy scripts, you learn a real programming language that you can later use to write your own programs. 19 | 20 | ## Installation 21 | AutoHotPy doesn't really need any. You just place the scripts in the same folder and they just work. However, the libraries needed for it to run are not installed by default in any operative system. 22 | 23 | 1. Verify you have Python installed, if not, please install python to proceed 24 | 2. Install interception driver (and restart your computer): http://oblita.com/Interception.html 25 | hint: if double clicking in the executable doesn't install the driver (you will see an error message when you start AutoHotPy), try running a command line as administrator from the windows menu (right clicking on the program and selecting "Run as administrator"), and then go to your download location from the command line and run "install-interception.exe /install" 26 | 3. Place the .dll in the same place were you downloaded AutoHotPy. We need interception.dll to work! 27 | 28 | 29 | ## Intro 30 | Python is a real programming language, so remember: everything you learn while you write the scripts can be used to write your own programs! 31 | To use AutoHotPy you only have to write a script (patience!) and place it in the same folder where you installed the app. 32 | I will add more documentation later but lets get you working fast. 33 | 34 | 35 | Open "Example1-GameCombo.py". The first paragraph is the license, you don't need it in your scripts. 36 | Follow the comments (everything that is placed after #) to understand what's happening. 37 | 38 | 39 | "Example2-MultipleKeys.py": this example shows how to handle multiple keys pressed at the same time. 40 | The example opens the windows task manager (in windows 7) directly when you hit Ctr+Alt+Supr instead of taking you 41 | to the options screen. 42 | The trick is to remap Ctrl+Alt+Supr to Ctrl+Shift+Escape (that opens the task manager directly) 43 | There is literally no limit on how many pressed keys you can handle from AutoHotPy, but that doesn't mean the operative system won't have his own limitations. 44 | 45 | 46 | "Example3-MouseButtons.py": Handling mouse movement and clicks is the hardest part in AutoHotPy, but because you have to do each movement or click manually. 47 | 48 | "Example4-MouseMovement.py": Invert mouse axis 49 | 50 | "Example5-Macros.py": Shows how to record macros for keyboard and mouse 51 | 52 | "Example6-Macros2 - Gaming macros.py": Shows how to record macros for games, where the mouse starting position is important for the macro to success. 53 | 54 | "Example7-Macros3 - Saving macro to file.py": the title is quite descriptive. 55 | 56 | "Example8-Macros4 - Auto-repeating macros.py": what if you want to always repeat a macro in a game. 57 | Imagine something very boring, like a fishing in Argentum Online: U.press() -> click on water... repeat until you get tired, or bored. 58 | This example shows you how to repeat a macro automatically, until you disable it again, of course. 59 | 60 | "Example9-Macros5 - Record mouse only.py": You can record a macro saving only mouse activity if you want. when you replay it, it will start from the first keyboard event automatically, and your gestures will me repeated, ignoring all mouse activity. 61 | 62 | "Example10-Macros6 - Record keyboard only.py": Same as Example9, but this time the mouse is ignored and we only record the keyboard activity. 63 | 64 | IMPORTANT NOTE: 65 | Known bugs: 66 | * the script crashes after saving a macro to a file and then trying to run the macro again. Workaround: restart the application after saving a macro to a file. 67 | 68 | ## Running the scripts 69 | To run any of the scripts open a command line and run "python .py". That's all you need. 70 | 71 | Be patient! Don't panic if you need help with the language, there are many python developers around the world. 72 | You will find help in any language you can image. 73 | 74 | 75 | 76 | Copyright 2012-2019 Emilio Moretti 77 | This program is distributed under the terms of the GNU Lesser General Public License. 78 | -------------------------------------------------------------------------------- /scancodes.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dc740/AutoHotPy/1f751d1aa0c7c264e5b29a9e13a4dea3cab11407/scancodes.ods --------------------------------------------------------------------------------