[HTML / JS ] Any way to capture XBOX inputs?

Dear Asobo, Is there any way to capture via .JS if an user has for example
clicked over the HTML / .JS gauge or in game panel one of the buttons of the
XBOX Controller? such as LB, RB, B, O, etc. We are working on a project now
intended for XBOX and PC market and it would be useful if we could capture
these events to perform certain actions / callbacks. Thanks in advance for any
help. Raul

Hello @Simbol No, the way to go is key events as
every input is supposed to be exposed in the control options. We have plans to
allow the creation of custom events that would be exposed in the options but
no ETA on this. Regards, Sylvain

Hi @FlyingRaccoon Sylvain, Thanks for the
quick response, just to confirm if I follow your response. Can we map a key
event of controls via JavaScript? that could work too… if so how we do this?.
In passing this is a stand alone module, so no aircraft code (model
behaviours) is possible to be used, we can use WASM stand alone module or HTML
/ JS in game panels code. Thanks, Raul

We are unable to find any of the events we need in the documentation.

Hello @Simbol No you can’t. You can send key events
using SetSimVarValue, and if you need to watch an event, you can watch when
the corresponding simvar value changes. Regards, Sylvain

Got you, thanks for the clarification. Best, Raul

@Symbol, As @Sylvain correctly mentions, you would want to use the sim’s key
events here if you’re looking to perform specific actions when sim events
happen, and not try to capture specific XBox controller inputs. However, it
is indeed possible in Javascript to intercept sim key events (here
intercepting the AP toggle key command, as a very very basic example):

      1. RegisterViewListener('JS_LISTENER_KEYEVENT', () => {
  2.   Coherent.call('INTERCEPT_KEY_EVENT', 'AP_MASTER', false);
  3.   Coherent.on('keyIntercepted', (key, index, value) => {
  4.     if (key === 'AP_MASTER') {
  5.       //Do some action
  6.     }
  7.   });
  8. });

If you are just looking to get the platform agnostic “click” events (clicks on
PC and by default A and B button on gamepads), you can simply bind to the
normal onclick, onmousedown, or onmouseup events on HTML elements and operate
as if you got right and left mouse button events. This will work on both
platforms. FYI: in order to get click passthrough to VC instruments, you need
a property on your base instrument class called isInteractive that returns
true. This is not required for InGamePanels. -Matt

Hi Matt, Thanks for this wonderful example, it will help us with other parts
of the project and other projects. We are trying to capture when an Xbox
controller button L1 or button L2 is pressed, this is because the software we
are developing as a “in game” panel has some features to handle certain
behaviours that are very easy with a PC mouse. For example the center wheel
scroll, which we can capture in JS and react accordingly and we perform
specific events in the in game panel UI we are creating, however since XBOX
users don’t have a mouse, we were trying to capture if they are pressing L1,
L2, etc. while having the panel loaded to replicate what happens when a user
press the mouse scroll wheel. Hope this extra explanation now makes sense to
you an Sylvain regarding what we are trying to do, basically we want to make
the XBOX users UI experience very easy with their own controllers pads while
using the in game panel. Thanks for all the help guys, Regards, Raul

The “mouse emulation” is already built into the UI layer on the sim side. When
the user uses the right stick up and down with the controller cursor inside
the element you will receive normal mouse wheel events on the HTML side.
Similarly, as I mentioned, you get normal mouse button events when the user
has the left stick cursor inside an element and presses the A or B buttons. In
other words, if you just pretend it’s a normal “web page”, the controller
stuff will be translated properly automatically without anything for you to
do. You can test this all using a XBox controller on the PC. -Matt

Hi Matt, Yea we got all the clicks working via Xbox, etc., but for what we are
building, the usage of L1 / L2, R2, etc. would work way better for the user
under some circumstances that as all. Many thanks for taking the time to come
and help. Best, Raul

Thanks @mattnischan for the input. Good to know you can watch the key events
in JS. My bad for the incorrect answer. That said, unless I’m missing
something, I don’t think you’ll be able to achieve what you want @Simbol. The
buttons you’re referring are already bound to actions in the game that don’t
always have a corresponding key event. And even when they do, how would you
handle a conflict with the game? The only proper way to do this would be to
allow 3rd parties to create events that would appear in the control options
and that player could bind their controller input to. Regards, Sylvain

Thanks Sylvain, We are coping so far by putting buttons on the panel for Xbox
users to make their life easier. Best, Raul


      1.     1. RegisterViewListener('JS_LISTENER_KEYEVENT', () => {
        2.   Coherent.call('INTERCEPT_KEY_EVENT', 'AP_MASTER', false);
        3.   Coherent.on('keyIntercepted', (key, index, value) => {
        4.     if (key === 'AP_MASTER') {
        5.       //Do some action
        6.     }
        7.   });
        8. });

will make it into the SDK, so everyone can be aware of this. As of this date,
only a few Developers seem to be using it … (if it is there, I cannot find
it, although I do remember it being mentioned in a SDK Update feature list
some time ago. - ) Matt & Dominic were kind enough to help me some 6 months
ago, and pointed me towards the above, as they were using it in their NXI, but
I have not seen but a small few using it . Also, has the " false", “true”
parameter been implemented yet to turn ON/OFF the Intercept ?