Python 模拟键盘输入

Python 模拟键盘输入,留着备用。

#coding=utf-8
import win32gui,win32api,win32con
import time
import threading

def key():
    interval = 0.3
    while True:
        time.sleep(interval )

        win32api.keybd_event(65,0,0,0) #a键位码是86
        win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0)

        win32api.keybd_event(83,0,0,0) #s键位码是86
        win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)

        win32api.keybd_event(68,0,0,0) #d键位码是86
        win32api.keybd_event(68,0,win32con.KEYEVENTF_KEYUP,0)

        win32api.keybd_event(74,0,0,0) #j键位码是86
        win32api.keybd_event(74,0,win32con.KEYEVENTF_KEYUP,0)

        win32api.keybd_event(75,0,0,0) #k键位码是86
        win32api.keybd_event(75,0,win32con.KEYEVENTF_KEYUP,0)

        win32api.keybd_event(76,0,0,0) #l键位码是86 

        win32api.keybd_event(76,0,win32con.KEYEVENTF_KEYUP,0)

t = threading.Thread(target=key)
t.start()



你可能感兴趣的:(Python)