Request Documentation for SU4: Ability to intercept and mask key events has been added to the JS key event listener

Please can we have some documentation or examples on how to implement

  • Ability to intercept and mask key events has been added to the JS key event listener .

** ** (as added in Sim Update #4)** __** I did get a little help with this,
but so far, I have not been able to successfully intercept Key Events ie the
correct use of::

      1. (1) RegisterViewListener('JS_LISTENER_KEYEVENT')
  2.  
  3. (2) listener.on('keyIntercepted', keyEventName => {
  4.   5. (3) Coherent.call('INTERCEPT_KEY_EVENT', 'AP_NAV1_HOLD', 1);

and anything else needed to intercept key events Currently, I cannot find any
mention of this in the SDK, or anywhere else I have searched, including all
the MSFS JS files currently on my PC.

One thing I see here… You might have to take care to do your subscriptions
in the callback of RegisterViewListener. When you do it immediately after
the call it might not be registered yet. Something like

      1. this.keyListener = RegisterViewListener('JS_LISTENER_KEYEVENT', () => {
  2.       Coherent.call('INTERCEPT_KEY_EVENT', 'AP_NAV1_HOLD', 1);
  3.       this.keyListener.on('keyIntercepted', this.handleKeyIntercepted);
  4.     });

Thanks dga, I still have not got this to work, which is why I was looking for
a working code example. When this got added in SU4, surely there was some
example test code created, to verify that this actually works as expected ?
Looking for an example of the use of this:- I can see in some js files,
instances of RegisterViewListener(‘JS_LISTENER_KEYEVENT’ but then, no
instances of Coherent.call(‘INTERCEPT_KEY_EVENT’,

      1.

It is currently not used in any stock avionics. It was an addition to give
addon developers more possibilities to handle K Events on the JS side for the
future. I gave you a working example in my answer above. You have to add your
callback method (handleKeyIntercepted) in my example and handle the event
there.

Thanks Matt & Dominic (WT), Finally got it figured out and working !!! Great
addition to the MSFS JS toolkit :slight_smile:

In the spirit of sharing, and not keeping technical secrets from others, this
is my example of the code I ended up getting to work. (It could do with a
little optimizing !!) The design aim was to be able to allow the Garmin
GNS530, to respond to Events being generated by another gauge, the VOR1 OBS
knob, without constantly polling the VOR1 OBS knob it in the update loop,

Any progress in adding the ability to Stop listening, or any idea which Update
it might be added in ? ie SU5 maybe ???

Thanks for this useful answer. Do you know what is the third parameter for? I
see it is set to 1 in your sample, I used the same function with 0 and it
works as well.

As I would like to know more about this feature, can you please tell me where
it is documented? I couldn’t find it anywhere in the SDK. Thank you.

I do not believe it is yet in the SDK documentation. I found out what i found
out by looking at the WT’s Nxi, that introduced this functionality into MSFS,
and some kind help and assistnce from Matt & DGA. I think the 3rd paramter, is
for some control to register/unregister, but at the moment. I believe it is
ignored, and the only thing you can do is register -(ie Unregister is not
supported yet)