Guest User

source

a guest
Feb 22nd, 2019
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. import pythoncom, pyHook
  2. import time
  3. import ctypes
  4. import csv
  5. with open('settings.csv') as f:
  6.     d = dict(filter(None, csv.reader(f)))
  7.  
  8. # C struct redefinitions
  9. PUL = ctypes.POINTER(ctypes.c_ulong)
  10. class KeyBdInput(ctypes.Structure):
  11.     _fields_ = [("wVk", ctypes.c_ushort),
  12.                 ("wScan", ctypes.c_ushort),
  13.                 ("dwFlags", ctypes.c_ulong),
  14.                 ("time", ctypes.c_ulong),
  15.                 ("dwExtraInfo", PUL)]
  16.  
  17. class HardwareInput(ctypes.Structure):
  18.     _fields_ = [("uMsg", ctypes.c_ulong),
  19.                 ("wParamL", ctypes.c_short),
  20.                 ("wParamH", ctypes.c_ushort)]
  21.  
  22. class MouseInput(ctypes.Structure):
  23.     _fields_ = [("dx", ctypes.c_long),
  24.                 ("dy", ctypes.c_long),
  25.                 ("mouseData", ctypes.c_ulong),
  26.                 ("dwFlags", ctypes.c_ulong),
  27.                 ("time",ctypes.c_ulong),
  28.                 ("dwExtraInfo", PUL)]
  29.  
  30. class Input_I(ctypes.Union):
  31.     _fields_ = [("ki", KeyBdInput),
  32.                  ("mi", MouseInput),
  33.                  ("hi", HardwareInput)]
  34.  
  35. class Input(ctypes.Structure):
  36.     _fields_ = [("type", ctypes.c_ulong),
  37.                 ("ii", Input_I)]
  38.  
  39. # Actuals Functions
  40.  
  41. def PressKey(hexKeyCode):
  42.     extra = ctypes.c_ulong(0)
  43.     ii_ = Input_I()
  44.     ii_.ki = KeyBdInput( 0, hexKeyCode, 0x0008, 0, ctypes.pointer(extra) )
  45.     x = Input( ctypes.c_ulong(1), ii_ )
  46.     ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
  47.  
  48. def ReleaseKey(hexKeyCode):
  49.     extra = ctypes.c_ulong(0)
  50.     ii_ = Input_I()
  51.     ii_.ki = KeyBdInput( 0, hexKeyCode, 0x0008 | 0x0002, 0, ctypes.pointer(extra) )
  52.     x = Input( ctypes.c_ulong(1), ii_ )
  53.     ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
  54.  
  55.  
  56. running = False
  57.  
  58. def dragMouse():
  59.     global d
  60.     duration = float(d['duration'])
  61.     sleep = float(d['sleep'])
  62.     y = int(d['yspeed'])
  63.     x = int(d['xspeed'])
  64.     iwait = float(d['initialwait'])
  65.    
  66.     global running
  67.    
  68.     if (running):
  69.         return
  70.  
  71.     print('Launching...')
  72.     running = True
  73.     then = time.time() + duration
  74.     PressKey(0x22)
  75.     time.sleep(iwait)
  76.     ctypes.windll.user32.mouse_event(1, 0, -10000, 0,0)
  77.     while(time.time() < then):
  78.          ctypes.windll.user32.mouse_event(1, x, -y, 0,0)
  79.          time.sleep(sleep)
  80.     ReleaseKey(0x22)
  81.     running = False
  82.     print('Done launching...')
  83.    
  84. def OnKeyboardEvent(event):
  85.     key = event.Key
  86.     if (key=='Up'):
  87.         dragMouse()
  88.        
  89. # return True to pass the event to other handlers
  90.     return True
  91.  
  92. # create a hook manager
  93. hm = pyHook.HookManager()
  94. # watch for all mouse events
  95. hm.KeyDown = OnKeyboardEvent
  96. # set the hook
  97. hm.HookKeyboard()
  98. # wait forever
  99. pythoncom.PumpMessages()
Add Comment
Please, Sign In to add comment