Advertisement
Guest User

Untitled

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