How to generate keyboard events in Python?

后端 未结 11 1176
有刺的猬
有刺的猬 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:19

    Every platform is going to have a different approach to being able to generate keyboard events. This is because they each need to make use of system libraries (and system extensions). For a cross platform solution, you would need to take each of these solutions and wrap then into a platform check to perform the proper approach.

    For windows, you might be able to use the pywin32 extension. win32api.keybd_event

    win32api.keybd_event

    keybd_event(bVk, bScan, dwFlags, dwExtraInfo)

    Simulate a keyboard event

    Parameters

    bVk : BYTE - Virtual-key code
    bScan : BYTE - Hardware scan code
    dwFlags=0 : DWORD - Flags specifying various function options
    dwExtraInfo=0 : DWORD - Additional data associated with keystroke

    You will need to investigate pywin32 for how to properly use it, as I have never used it.

提交回复
热议问题