I want to send a keyboard keystroke to active window, for example key A or Backspace using python. How can I do this?
I know active window coordinates as well (if it can help).
I want to send a keyboard keystroke to active window, for example key A or Backspace using python. How can I do this?
I know active window coordinates as well (if it can help).
The Windows API method to do this is SendInput which is part of the User32 library. It sends keyboard and mouse input to the foreground/active window. SendInput uses the INPUT structure, specifically called KEYBDINPUT. It has the option of sending more than one INPUT because the first parameter details that:
nInputs [in]
Type: UINT
The number of structures in the pInputs array.
An example of using SendInput in Python is specified in the answer on this question.
You use the MapVirtualKey function to map a virtual key code to a scan code