Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.84 KB | None | 0 0
  1. import ctypes
  2. import time
  3. user32 = ctypes.windll.user32
  4. inputhex = raw_input("Please enter your desired key's code (HEX): ")
  5. keycode = int(inputhex, 16)
  6. time.sleep(1)
  7. #VOID keybd_event(BYTE bVk, BYTE bScan, DWORD dwFlags, PTR dwExtraInfo);
  8. user32.keybd_event(keycode,0,2,0) #is the code for KEYDOWN
  9. time.sleep(5)
  10. #user32.keybd_event(keycode,0,0,0) #is the code for KEYDUP[/code]
  11.  
  12. import ctypes
  13.  
  14. LONG = ctypes.c_long
  15. DWORD = ctypes.c_ulong
  16. ULONG_PTR = ctypes.POINTER(DWORD)
  17. WORD = ctypes.c_ushort
  18.  
  19. class MOUSEINPUT(ctypes.Structure):
  20. _fields_ = (('dx', LONG),
  21. ('dy', LONG),
  22. ('mouseData', DWORD),
  23. ('dwFlags', DWORD),
  24. ('time', DWORD),
  25. ('dwExtraInfo', ULONG_PTR))
  26.  
  27. class KEYBDINPUT(ctypes.Structure):
  28. _fields_ = (('wVk', WORD),
  29. ('wScan', WORD),
  30. ('dwFlags', DWORD),
  31. ('time', DWORD),
  32. ('dwExtraInfo', ULONG_PTR))
  33.  
  34. class HARDWAREINPUT(ctypes.Structure):
  35. _fields_ = (('uMsg', DWORD),
  36. ('wParamL', WORD),
  37. ('wParamH', WORD))
  38.  
  39. class _INPUTunion(ctypes.Union):
  40. _fields_ = (('mi', MOUSEINPUT),
  41. ('ki', KEYBDINPUT),
  42. ('hi', HARDWAREINPUT))
  43.  
  44. class INPUT(ctypes.Structure):
  45. _fields_ = (('type', DWORD),
  46. ('union', _INPUTunion))
  47.  
  48. def SendInput(*inputs):
  49. nInputs = len(inputs)
  50. LPINPUT = INPUT * nInputs
  51. pInputs = LPINPUT(*inputs)
  52. cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
  53. return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)
  54.  
  55. INPUT_MOUSE = 0
  56. INPUT_KEYBOARD = 1
  57. INPUT_HARDWARD = 2
  58.  
  59. def Input(structure):
  60. if isinstance(structure, MOUSEINPUT):
  61. return INPUT(INPUT_MOUSE, _INPUTunion(mi=structure))
  62. if isinstance(structure, KEYBDINPUT):
  63. return INPUT(INPUT_KEYBOARD, _INPUTunion(ki=structure))
  64. if isinstance(structure, HARDWAREINPUT):
  65. return INPUT(INPUT_HARDWARE, _INPUTunion(hi=structure))
  66. raise TypeError('Cannot create INPUT structure!')
  67.  
  68. WHEEL_DELTA = 120
  69. XBUTTON1 = 0x0001
  70. XBUTTON2 = 0x0002
  71. MOUSEEVENTF_ABSOLUTE = 0x8000
  72. MOUSEEVENTF_HWHEEL = 0x01000
  73. MOUSEEVENTF_MOVE = 0x0001
  74. MOUSEEVENTF_MOVE_NOCOALESCE = 0x2000
  75. MOUSEEVENTF_LEFTDOWN = 0x0002
  76. MOUSEEVENTF_LEFTUP = 0x0004
  77. MOUSEEVENTF_RIGHTDOWN = 0x0008
  78. MOUSEEVENTF_RIGHTUP = 0x0010
  79. MOUSEEVENTF_MIDDLEDOWN = 0x0020
  80. MOUSEEVENTF_MIDDLEUP = 0x0040
  81. MOUSEEVENTF_VIRTUALDESK = 0x4000
  82. MOUSEEVENTF_WHEEL = 0x0800
  83. MOUSEEVENTF_XDOWN = 0x0080
  84. MOUSEEVENTF_XUP = 0x0100
  85.  
  86. def MouseInput(flags, x, y, data):
  87. return MOUSEINPUT(x, y, data, flags, 0, None)
  88.  
  89. VK_LBUTTON = 0x01 # Left mouse button
  90. VK_RBUTTON = 0x02 # Right mouse button
  91. VK_CANCEL = 0x03 # Control-break processing
  92. VK_MBUTTON = 0x04 # Middle mouse button (three-button mouse)
  93. VK_XBUTTON1 = 0x05 # X1 mouse button
  94. VK_XBUTTON2 = 0x06 # X2 mouse button
  95. VK_BACK = 0x08 # BACKSPACE key
  96. VK_TAB = 0x09 # TAB key
  97. VK_CLEAR = 0x0C # CLEAR key
  98. VK_RETURN = 0x0D # ENTER key
  99. VK_SHIFT = 0x10 # SHIFT key
  100. VK_CONTROL = 0x11 # CTRL key
  101. VK_MENU = 0x12 # ALT key
  102. VK_PAUSE = 0x13 # PAUSE key
  103. VK_CAPITAL = 0x14 # CAPS LOCK key
  104. VK_KANA = 0x15 # IME Kana mode
  105. VK_HANGUL = 0x15 # IME Hangul mode
  106. VK_JUNJA = 0x17 # IME Junja mode
  107. VK_FINAL = 0x18 # IME final mode
  108. VK_HANJA = 0x19 # IME Hanja mode
  109. VK_KANJI = 0x19 # IME Kanji mode
  110. VK_ESCAPE = 0x1B # ESC key
  111. VK_CONVERT = 0x1C # IME convert
  112. VK_NONCONVERT = 0x1D # IME nonconvert
  113. VK_ACCEPT = 0x1E # IME accept
  114. VK_MODECHANGE = 0x1F # IME mode change request
  115. VK_SPACE = 0x20 # SPACEBAR
  116. VK_PRIOR = 0x21 # PAGE UP key
  117. VK_NEXT = 0x22 # PAGE DOWN key
  118. VK_END = 0x23 # END key
  119. VK_HOME = 0x24 # HOME key
  120. VK_LEFT = 0x25 # LEFT ARROW key
  121. VK_UP = 0x26 # UP ARROW key
  122. VK_RIGHT = 0x27 # RIGHT ARROW key
  123. VK_DOWN = 0x28 # DOWN ARROW key
  124. VK_SELECT = 0x29 # SELECT key
  125. VK_PRINT = 0x2A # PRINT key
  126. VK_EXECUTE = 0x2B # EXECUTE key
  127. VK_SNAPSHOT = 0x2C # PRINT SCREEN key
  128. VK_INSERT = 0x2D # INS key
  129. VK_DELETE = 0x2E # DEL key
  130. VK_HELP = 0x2F # HELP key
  131. VK_LWIN = 0x5B # Left Windows key (Natural keyboard)
  132. VK_RWIN = 0x5C # Right Windows key (Natural keyboard)
  133. VK_APPS = 0x5D # Applications key (Natural keyboard)
  134. VK_SLEEP = 0x5F # Computer Sleep key
  135. VK_NUMPAD0 = 0x60 # Numeric keypad 0 key
  136. VK_NUMPAD1 = 0x61 # Numeric keypad 1 key
  137. VK_NUMPAD2 = 0x62 # Numeric keypad 2 key
  138. VK_NUMPAD3 = 0x63 # Numeric keypad 3 key
  139. VK_NUMPAD4 = 0x64 # Numeric keypad 4 key
  140. VK_NUMPAD5 = 0x65 # Numeric keypad 5 key
  141. VK_NUMPAD6 = 0x66 # Numeric keypad 6 key
  142. VK_NUMPAD7 = 0x67 # Numeric keypad 7 key
  143. VK_NUMPAD8 = 0x68 # Numeric keypad 8 key
  144. VK_NUMPAD9 = 0x69 # Numeric keypad 9 key
  145. VK_MULTIPLY = 0x6A # Multiply key
  146. VK_ADD = 0x6B # Add key
  147. VK_SEPARATOR = 0x6C # Separator key
  148. VK_SUBTRACT = 0x6D # Subtract key
  149. VK_DECIMAL = 0x6E # Decimal key
  150. VK_DIVIDE = 0x6F # Divide key
  151. VK_F1 = 0x70 # F1 key
  152. VK_F2 = 0x71 # F2 key
  153. VK_F3 = 0x72 # F3 key
  154. VK_F4 = 0x73 # F4 key
  155. VK_F5 = 0x74 # F5 key
  156. VK_F6 = 0x75 # F6 key
  157. VK_F7 = 0x76 # F7 key
  158. VK_F8 = 0x77 # F8 key
  159. VK_F9 = 0x78 # F9 key
  160. VK_F10 = 0x79 # F10 key
  161. VK_F11 = 0x7A # F11 key
  162. VK_F12 = 0x7B # F12 key
  163. VK_F13 = 0x7C # F13 key
  164. VK_F14 = 0x7D # F14 key
  165. VK_F15 = 0x7E # F15 key
  166. VK_F16 = 0x7F # F16 key
  167. VK_F17 = 0x80 # F17 key
  168. VK_F18 = 0x81 # F18 key
  169. VK_F19 = 0x82 # F19 key
  170. VK_F20 = 0x83 # F20 key
  171. VK_F21 = 0x84 # F21 key
  172. VK_F22 = 0x85 # F22 key
  173. VK_F23 = 0x86 # F23 key
  174. VK_F24 = 0x87 # F24 key
  175. VK_NUMLOCK = 0x90 # NUM LOCK key
  176. VK_SCROLL = 0x91 # SCROLL LOCK key
  177. VK_LSHIFT = 0xA0 # Left SHIFT key
  178. VK_RSHIFT = 0xA1 # Right SHIFT key
  179. VK_LCONTROL = 0xA2 # Left CONTROL key
  180. VK_RCONTROL = 0xA3 # Right CONTROL key
  181. VK_LMENU = 0xA4 # Left MENU key
  182. VK_RMENU = 0xA5 # Right MENU key
  183. VK_BROWSER_BACK = 0xA6 # Browser Back key
  184. VK_BROWSER_FORWARD = 0xA7 # Browser Forward key
  185. VK_BROWSER_REFRESH = 0xA8 # Browser Refresh key
  186. VK_BROWSER_STOP = 0xA9 # Browser Stop key
  187. VK_BROWSER_SEARCH = 0xAA # Browser Search key
  188. VK_BROWSER_FAVORITES = 0xAB # Browser Favorites key
  189. VK_BROWSER_HOME = 0xAC # Browser Start and Home key
  190. VK_VOLUME_MUTE = 0xAD # Volume Mute key
  191. VK_VOLUME_DOWN = 0xAE # Volume Down key
  192. VK_VOLUME_UP = 0xAF # Volume Up key
  193. VK_MEDIA_NEXT_TRACK = 0xB0 # Next Track key
  194. VK_MEDIA_PREV_TRACK = 0xB1 # Previous Track key
  195. VK_MEDIA_STOP = 0xB2 # Stop Media key
  196. VK_MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media key
  197. VK_LAUNCH_MAIL = 0xB4 # Start Mail key
  198. VK_LAUNCH_MEDIA_SELECT = 0xB5 # Select Media key
  199. VK_LAUNCH_APP1 = 0xB6 # Start Application 1 key
  200. VK_LAUNCH_APP2 = 0xB7 # Start Application 2 key
  201. VK_OEM_1 = 0xBA # Used for miscellaneous characters; it can vary by keyboard.
  202. # For the US standard keyboard, the ';:' key
  203. VK_OEM_PLUS = 0xBB # For any country/region, the '+' key
  204. VK_OEM_COMMA = 0xBC # For any country/region, the ',' key
  205. VK_OEM_MINUS = 0xBD # For any country/region, the '-' key
  206. VK_OEM_PERIOD = 0xBE # For any country/region, the '.' key
  207. VK_OEM_2 = 0xBF # Used for miscellaneous characters; it can vary by keyboard.
  208. # For the US standard keyboard, the '/?' key
  209. VK_OEM_3 = 0xC0 # Used for miscellaneous characters; it can vary by keyboard.
  210. # For the US standard keyboard, the '`~' key
  211. VK_OEM_4 = 0xDB # Used for miscellaneous characters; it can vary by keyboard.
  212. # For the US standard keyboard, the '[{' key
  213. VK_OEM_5 = 0xDC # Used for miscellaneous characters; it can vary by keyboard.
  214. # For the US standard keyboard, the '|' key
  215. VK_OEM_6 = 0xDD # Used for miscellaneous characters; it can vary by keyboard.
  216. # For the US standard keyboard, the ']}' key
  217. VK_OEM_7 = 0xDE # Used for miscellaneous characters; it can vary by keyboard.
  218. # For the US standard keyboard, the 'single-quote/double-quote' key
  219. VK_OEM_8 = 0xDF # Used for miscellaneous characters; it can vary by keyboard.
  220. VK_OEM_102 = 0xE2 # Either the angle bracket key or the backslash key on the RT 102-key keyboard
  221. VK_PROCESSKEY = 0xE5 # IME PROCESS key
  222. VK_PACKET = 0xE7 # Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
  223. VK_ATTN = 0xF6 # Attn key
  224. VK_CRSEL = 0xF7 # CrSel key
  225. VK_EXSEL = 0xF8 # ExSel key
  226. VK_EREOF = 0xF9 # Erase EOF key
  227. VK_PLAY = 0xFA # Play key
  228. VK_ZOOM = 0xFB # Zoom key
  229. VK_PA1 = 0xFD # PA1 key
  230. VK_OEM_CLEAR = 0xFE # Clear key
  231.  
  232. KEYEVENTF_EXTENDEDKEY = 0x0001
  233. KEYEVENTF_KEYUP = 0x0002
  234. KEYEVENTF_SCANCODE = 0x0008
  235. KEYEVENTF_UNICODE = 0x0004
  236.  
  237. KEY_0 = 0x30
  238. KEY_1 = 0x31
  239. KEY_2 = 0x32
  240. KEY_3 = 0x33
  241. KEY_4 = 0x34
  242. KEY_5 = 0x35
  243. KEY_6 = 0x36
  244. KEY_7 = 0x37
  245. KEY_8 = 0x38
  246. KEY_9 = 0x39
  247. KEY_A = 0x41
  248. KEY_B = 0x42
  249. KEY_C = 0x43
  250. KEY_D = 0x44
  251. KEY_E = 0x45
  252. KEY_F = 0x46
  253. KEY_G = 0x47
  254. KEY_H = 0x48
  255. KEY_I = 0x49
  256. KEY_J = 0x4A
  257. KEY_K = 0x4B
  258. KEY_L = 0x4C
  259. KEY_M = 0x4D
  260. KEY_N = 0x4E
  261. KEY_O = 0x4F
  262. KEY_P = 0x50
  263. KEY_Q = 0x51
  264. KEY_R = 0x52
  265. KEY_S = 0x53
  266. KEY_T = 0x54
  267. KEY_U = 0x55
  268. KEY_V = 0x56
  269. KEY_W = 0x57
  270. KEY_X = 0x58
  271. KEY_Y = 0x59
  272. KEY_Z = 0x5A
  273.  
  274. def KeybdInput(code, flags):
  275. return KEYBDINPUT(code, code, flags, 0, None)
  276.  
  277. def HardwareInput(message, parameter):
  278. return HARDWAREINPUT(message & 0xFFFFFFFF,
  279. parameter & 0xFFFF,
  280. parameter >> 16 & 0xFFFF)
  281.  
  282. def Mouse(flags, x=0, y=0, data=0):
  283. return Input(MouseInput(flags, x, y, data))
  284.  
  285. def Keyboard(code, flags=0):
  286. return Input(KeybdInput(code, flags))
  287.  
  288. def Hardware(message, parameter=0):
  289. return Input(HardwareInput(message, parameter))
  290.  
  291. ################################################################################
  292.  
  293. import string
  294.  
  295. UPPER = frozenset('~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?')
  296. LOWER = frozenset("`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./")
  297. ORDER = string.ascii_letters + string.digits + ' brt'
  298. ALTER = dict(zip('!@#$%^&*()', '1234567890'))
  299. OTHER = {'`': VK_OEM_3,
  300. '~': VK_OEM_3,
  301. '-': VK_OEM_MINUS,
  302. '_': VK_OEM_MINUS,
  303. '=': VK_OEM_PLUS,
  304. '+': VK_OEM_PLUS,
  305. '[': VK_OEM_4,
  306. '{': VK_OEM_4,
  307. ']': VK_OEM_6,
  308. '}': VK_OEM_6,
  309. '\': VK_OEM_5,
  310. '|': VK_OEM_5,
  311. ';': VK_OEM_1,
  312. ':': VK_OEM_1,
  313. "'": VK_OEM_7,
  314. '"': VK_OEM_7,
  315. ',': VK_OEM_COMMA,
  316. '<': VK_OEM_COMMA,
  317. '.': VK_OEM_PERIOD,
  318. '>': VK_OEM_PERIOD,
  319. '/': VK_OEM_2,
  320. '?': VK_OEM_2}
  321.  
  322. def keyboard_stream(string):
  323. mode = False
  324. for character in string.replace('rn', 'r').replace('n', 'r'):
  325. if mode and character in LOWER or not mode and character in UPPER:
  326. yield Keyboard(VK_SHIFT, mode and KEYEVENTF_KEYUP)
  327. mode = not mode
  328. character = ALTER.get(character, character)
  329. if character in ORDER:
  330. code = ord(character.upper())
  331. elif character in OTHER:
  332. code = OTHER[character]
  333. else:
  334. continue
  335. raise ValueError('String is not understood!')
  336. yield Keyboard(code)
  337. yield Keyboard(code, KEYEVENTF_KEYUP)
  338. if mode:
  339. yield Keyboard(VK_SHIFT, KEYEVENTF_KEYUP)
  340.  
  341. ################################################################################
  342.  
  343. import time, sys
  344.  
  345. def main():
  346. time.sleep(5)
  347. for event in keyboard_stream('o2E^uXh#:SHn&HQ+t]YF'):
  348. SendInput(event)
  349. time.sleep(0.1)
  350.  
  351. ##if __name__ == '__main__':
  352. ## main()
  353.  
  354. def switch_program():
  355. SendInput(Keyboard(VK_MENU), Keyboard(VK_TAB))
  356. time.sleep(0.2)
  357. SendInput(Keyboard(VK_TAB, KEYEVENTF_KEYUP),
  358. Keyboard(VK_MENU, KEYEVENTF_KEYUP))
  359. time.sleep(0.2)
  360.  
  361. def select_line():
  362. SendInput(Keyboard(VK_SHIFT, KEYEVENTF_EXTENDEDKEY),
  363. Keyboard(VK_END, KEYEVENTF_EXTENDEDKEY))
  364. time.sleep(0.2)
  365. SendInput(Keyboard(VK_SHIFT, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP),
  366. Keyboard(VK_END, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP))
  367. time.sleep(0.2)
  368.  
  369. def copy_line():
  370. SendInput(Keyboard(VK_CONTROL), Keyboard(KEY_C))
  371. time.sleep(0.2)
  372. SendInput(Keyboard(VK_CONTROL, KEYEVENTF_KEYUP),
  373. Keyboard(KEY_C, KEYEVENTF_KEYUP))
  374. time.sleep(0.2)
  375.  
  376. def next_line():
  377. SendInput(Keyboard(VK_HOME), Keyboard(VK_DOWN))
  378. time.sleep(0.2)
  379. SendInput(Keyboard(VK_HOME, KEYEVENTF_KEYUP),
  380. Keyboard(VK_DOWN, KEYEVENTF_KEYUP))
  381. time.sleep(0.2)
  382.  
  383. def prepare_text():
  384. # Open Text
  385. SendInput(Keyboard(KEY_M))
  386. time.sleep(0.2)
  387. SendInput(Keyboard(KEY_M, KEYEVENTF_KEYUP))
  388. time.sleep(0.2)
  389. # Goto Area
  390. SendInput(Keyboard(VK_TAB))
  391. time.sleep(0.2)
  392. SendInput(Keyboard(VK_TAB, KEYEVENTF_KEYUP))
  393. time.sleep(0.2)
  394. # Paste Message
  395. SendInput(Keyboard(VK_CONTROL), Keyboard(KEY_V))
  396. time.sleep(0.2)
  397. SendInput(Keyboard(VK_CONTROL, KEYEVENTF_KEYUP),
  398. Keyboard(KEY_V, KEYEVENTF_KEYUP))
  399. time.sleep(0.2)
  400. # Goto Button
  401. SendInput(Keyboard(VK_TAB))
  402. time.sleep(0.2)
  403. SendInput(Keyboard(VK_TAB, KEYEVENTF_KEYUP))
  404. time.sleep(0.2)
  405.  
  406. def send_one_message():
  407. select_line()
  408. copy_line()
  409. next_line()
  410. switch_program()
  411. prepare_text()
  412. # Send Message
  413. SendInput(Keyboard(VK_RETURN))
  414. time.sleep(0.2)
  415. SendInput(Keyboard(VK_RETURN, KEYEVENTF_KEYUP))
  416. time.sleep(10)
  417. switch_program()
  418.  
  419. def send_messages(total):
  420. time.sleep(10)
  421. for _ in range(total):
  422. send_one_message()
  423.  
  424. >>> import win32api
  425. >>> import win32con
  426. >>> win32api.keybd_event(win32con.SHIFT_PRESSED, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
  427. >>> HELLO
  428.  
  429. # coding: utf-8
  430. """
  431. Simple unicode keyboard automation for windows
  432. Based off of http://stackoverflow.com/questions/11906925/python-simulate-keydown
  433. """
  434.  
  435. import ctypes
  436. import time
  437. import sys
  438.  
  439. LONG = ctypes.c_long
  440. DWORD = ctypes.c_ulong
  441. ULONG_PTR = ctypes.POINTER(DWORD)
  442. WORD = ctypes.c_ushort
  443.  
  444. INPUT_MOUSE = 0
  445. INPUT_KEYBOARD = 1
  446. INPUT_HARDWARE = 2
  447.  
  448. KEYEVENTF_EXTENDEDKEY = 0x0001
  449. KEYEVENTF_KEYUP = 0x0002
  450. KEYEVENTF_SCANCODE = 0x0008
  451. KEYEVENTF_UNICODE = 0x0004
  452.  
  453.  
  454. class MOUSEINPUT(ctypes.Structure):
  455. _fields_ = (('dx', LONG),
  456. ('dy', LONG),
  457. ('mouseData', DWORD),
  458. ('dwFlags', DWORD),
  459. ('time', DWORD),
  460. ('dwExtraInfo', ULONG_PTR))
  461.  
  462.  
  463. class KEYBDINPUT(ctypes.Structure):
  464. _fields_ = (('wVk', WORD),
  465. ('wScan', WORD),
  466. ('dwFlags', DWORD),
  467. ('time', DWORD),
  468. ('dwExtraInfo', ULONG_PTR))
  469.  
  470.  
  471. class HARDWAREINPUT(ctypes.Structure):
  472. _fields_ = (('uMsg', DWORD),
  473. ('wParamL', WORD),
  474. ('wParamH', WORD))
  475.  
  476.  
  477. class _INPUTunion(ctypes.Union):
  478. _fields_ = (('mi', MOUSEINPUT),
  479. ('ki', KEYBDINPUT),
  480. ('hi', HARDWAREINPUT))
  481.  
  482.  
  483. class INPUT(ctypes.Structure):
  484. _fields_ = (('type', DWORD),
  485. ('union', _INPUTunion))
  486.  
  487.  
  488. def send_input(*inputs):
  489. nInputs = len(inputs)
  490. LPINPUT = INPUT * nInputs
  491. pInputs = LPINPUT(*inputs)
  492. cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
  493. return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)
  494.  
  495.  
  496. def input_structure(structure):
  497. if isinstance(structure, MOUSEINPUT):
  498. return INPUT(INPUT_MOUSE, _INPUTunion(mi=structure))
  499. if isinstance(structure, KEYBDINPUT):
  500. return INPUT(INPUT_KEYBOARD, _INPUTunion(ki=structure))
  501. if isinstance(structure, HARDWAREINPUT):
  502. return INPUT(INPUT_HARDWARE, _INPUTunion(hi=structure))
  503. raise TypeError('Cannot create INPUT structure!')
  504.  
  505.  
  506. def keyboard_input(code, flags):
  507. return KEYBDINPUT(0, code, flags, 0, None)
  508.  
  509.  
  510. def keyboard_event(code, flags=KEYEVENTF_UNICODE):
  511. return input_structure(keyboard_input(code, flags))
  512.  
  513.  
  514. def press(character):
  515. code = ord(character)
  516. send_input(keyboard_event(code))
  517. send_input(keyboard_event(code, KEYEVENTF_KEYUP))
  518.  
  519.  
  520. def main():
  521. time.sleep(3)
  522. for char in u'Onשש2E6UXoשש2E^uXh#:SHn&HQ':
  523. press(char)
  524. time.sleep(0.5)
  525.  
  526. if __name__ == '__main__':
  527. main()
  528.  
  529. #imports the library
  530. from pykeyboard import PyKeyboard
  531. #import the sleep function
  532. from time import sleep
  533. #initialize the keyboard simulator
  534. keyboard = PyKeyboard()
  535. #presses the key
  536. keyboard.press_key('x')
  537. #waits five seconds before releasing the key
  538. sleep(5)
  539. #releases the key
  540. keyboard.release_key('x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement