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).

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.

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

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/t/3221 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