One 、Python Keyboard input simulation : import win32api import win32con win32api.keybd_event(17,0,0,0) #ctrl The key location code is 17 win32api.keybd_event(86,0,0,0) #v The key location code is 86 win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) # Release the button win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0) Attach a key code table :
Letters and numbers The keys of the numeric keypad Function keys Other keys
key Key code key Key code key Key code key Key code
A 65 0 96 F1 112 Backspace 8
B 66 1 97 F2 113 Tab 9
C 67 2 98 F3 114 Clear 12
D 68 3 99 F4 115 Enter 13
E 69 4 100 F5 116 Shift 16
F 70 5 101 F6 117 Control 17
G 71 6 102 F7 118 Alt 18
H 72 7 103 F8 119 Caps Lock 20
I 73 8 104 F9 120 Esc 27
J 74 9 105 F10 121 Spacebar 32
K 75 * 106 F11 122 Page Up 33
L 76 + 107 F12 123 Page Down 34
M 77 Enter 108 -- -- End 35
N 78 - 109 -- -- Home 36
O 79 . 110 -- -- Left Arrow 37
P 80 / 111 -- -- Up Arrow 38
Q 81 -- -- -- -- Right Arrow 39
R 82 -- -- -- -- Down Arrow 40
S 83 -- -- -- -- Insert 45
T 84 -- -- -- -- Delete 46
U 85 -- -- -- -- Help 47
V 86 -- -- -- -- Num Lock 144
Other unlisted alphanumeric keyboards are :ord(c)
Two 、 Use windll.user32 Implement mouse emulation :
from ctypes import * windll.user32.SetCursorPos(100, 100)
3、 ... and . Use AutoItX Implement mouse emulation :
# take AutoItX3.dll File copy to Windows Directory and then register regsvr32.exe AutoItX3.dll
from win32com.client import Dispatch def enter_game(): AutoItX = Dispatch( "AutoItX3.Control" ) # Block All Input AutoItX.BlockInput( 1 ) AutoItX.Sleep( 20000 ) if AutoItX.WinActivate( GAME_WINDOW_TITLE, '' ): pass else: if AutoItX.WinWaitActive( GAME_WINDOW_TITLE, '', 8 ): pass else: # Unblock input AutoItX.BlockInput( 0 ) return False AutoItX.WinSetTitle( GAME_WINDOW_TITLE, '', _pre_title ) AutoItX.WinSetState( _pre_title, '', AutoItX.SW_MAXIMIZE ) AutoItX.Sleep( 5000 ) AutoItX.MouseMove( 462, 396, 10 ) AutoItX.MouseClick( "left" ) AutoItX.Sleep( 1000 ) AutoItX.Send( GAME_ACCT_NAME ) AutoItX.Sleep( 1000 ) AutoItX.MouseMove ( 462, 472, 10 ) AutoItX.MouseClick( "left" ) AutoItX.Sleep( 1000 ) AutoItX.Send( GAME_ACCT_PASS ) AutoItX.Send( "{ENTER}" ) AutoItX.Sleep( 10000 ) # Unblock input AutoItX.BlockInput( 0 ) return True </pre>