I couldn’t find a better place for this, so thought I’d post in SDK to get developer input.
I’ve written a Python script and I want to send key presses to MSFS 2020, but NOT through the SDK. I am using pyautogui (and I’ve tried other libraries) to send press() and hotkey() commands to the active window of MSFS (I have confirmed MSFS is active). But sending key presses just doesn’t work. My code can send key presses to other apps (notepad, etc.).
I have asked ChatGPT and it suggests that some apps (maybe MSFS) restrict programmatic key presses. Does anyone know if this is true for MSFS?
I will use the SDK if necessary, but I was hoping to have my project interact ONLY with key presses via my script.
but FWIW I can confirm that trying to send key strokes to the MSFS window doesn’t work like it does for “traditional” Windows applications. I tried (a year or two ago) using direct Win32 API calls (eg. SendInput(), no intermediate libraries) and it just doesn’t work. It seems whatever window is presented as the main UI for MSFS doesn’t listen for keyboard/mouse messages like that.
EDIT: apparently this is incorrect, see reply fom E1ephant42below.
My next idea was to maybe create some kind of “virtual” keyboard that would act like a regular system keyboard so maybe MSFS would listen to that input at a lower level. But never got around to testing that theory.
The SDK contains an API called “Simconnect” which is used for all tools around and you are most likely limited to that when it comes down to interactions.
Check the Simconnect section on the SDK documentation for the events you can use (read, write, manipulate or set).
I’m sorry but this is absolutely false. There are countless applications that send keystrokes to MSFS at a low level - stream deck to name just one. My own custom app uses Win32 SendInput() to send low level key events to MSFS (and every other game that I play) without any issues at all.
@MojaveHigh2379 I’m fairly certain that you will be able to find some examples of Python code to send low level key events to MSFS. Something that might be causing issues is if your app takes focus away from MSFS in order to send the key events, then MSFS will of course not see them. If your app stays in the background then this will not be a problem but if your app takes focus in order to send the keystrokes then you will need code give focus back to MSFS BEFORE you send the key events - good luck.
No need to be sorry, indeed I must apologize that I gave incorrect information. I was also under the impression that other apps can have issues sending keys directly. Perhaps it is about window focus as you suggest. I’ll have to go back and see what I was doing wrong in my experiments (though ofc sim had focus in my tests). Thanks for the info and also for publishing your sources (FOSS FTW!).