plane icon Welcome to Microsoft Flight Simulator’s SDK Q&A Platform!

You have questions regarding the SDK? DevMode Tools? SimConnect? You would like to submit an idea for future improvements, seek help or exchange knowledge? You’re in the right place.

Please take a moment to read the platform’s guidelines before you get started!

question

Diagonalization avatar image
Diagonalization asked dga edited

Intercept key press in a toolbar addon?

Is it possible to write a toolbar panel addon that responds to custom key events? I would like to create what are effectively macros for common flows, and trigger them from the keyboard (or a joystick button, ideally).

defaulthtml
10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

1 Answer

· Write an Answer
dga avatar image
dga answered dga edited

Look into leveraging inputs.js.
It enables you to register an InputsListener, which allows you to poll for input states.

As an example you could look at the updateInputs() method in MapInstrument.js in asobo-vcockpits-instruments in the official packages.

Be aware that this doesn't allow to mask inputs. So it will still trigger bound key events with the sim.

2 comments
10 |10000 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Thanks this works. Here is a small snippet of code that prints "2" when the water rudder key is pressed:

setInterval(() => { 
   console.log(GetInputStatus("PLANE", "KEY_TOGGLE_WATER_RUDDER")); },
 500);


How do you figure out the magic strings for each key? Many of them are in the XML files in this directory:


C:\Program Files\WindowsApps\Microsoft.FlightSimulator_1.17.3.0_x64__8wekyb3d8bbwe\Input
0 Likes 0 ·
dga avatar image dga Diagonalization ·

Take a look on those pages in the docs

https://docs.flightsimulator.com/html/index.htm#t=Programming_Tools%2FSimConnect%2FStatus%2FStatus_Of_SimEvents.htm

https://docs.flightsimulator.com/html/index.htm#t=Programming_Tools%2FSimVars%2FLegacy_Event_IDs.htm

Also since you are looking into intercepting key events (i thought just characters). Take a look at this new API feature too (but in your case you shouldn't mask events)

https://devsupport.flightsimulator.com/questions/960/request-documentation-for-su4-ability-to-intercept.html

P.S.: I think SU5 will have an update to inputs.js which will allow a more event based approach instead of polling for it

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.