How to generate keyboard events in Python?

后端 未结 11 1192
有刺的猬
有刺的猬 2020-11-22 14:55

short summary:

I am trying to create a program that will send keyboard events to the computer that for all purposes the simulated events should be t

11条回答
  •  借酒劲吻你
    2020-11-22 15:40

    For Python2.7(windows32) I installed only pywin32-223. And I wrote simple python`s code:

    import win32api
    import time
    import win32con
    
    # simulate the pressing-DOWN "ARROW key" of 200 times
    
    for i in range(200):
       time.sleep(0.5)
       win32api.keybd_event(0x28, 0,0,0)
       time.sleep(.05)
       win32api.keybd_event(0x28,0 ,win32con.KEYEVENTF_KEYUP ,0)
    

    It can be checked if you run the code and immediately go to the notepad window (where the text already exists) and place the cursor on the top line.

提交回复
热议问题