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

Simbol avatar image
Simbol asked N6722C edited

[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

gauges
10 |10000

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

FlyingRaccoon avatar image
FlyingRaccoon answered Simbol commented

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

4 comments
10 |10000

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

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

0 Likes 0 ·
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

0 Likes 0 ·
Simbol avatar image Simbol FlyingRaccoon ♦♦ ·
Got you, thanks for the clarification.


Best,
Raul

0 Likes 0 ·

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

1653062783398.png

0 Likes 0 ·
1653062783398.png (83.3 KiB)
mattnischan avatar image
mattnischan answered Simbol commented

@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):

RegisterViewListener('JS_LISTENER_KEYEVENT', () => {
  Coherent.call('INTERCEPT_KEY_EVENT', 'AP_MASTER', false);
  Coherent.on('keyIntercepted', (key, index, value) => {
    if (key === 'AP_MASTER') {
      //Do some action
    }
  });
});

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

5 comments
10 |10000

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

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

0 Likes 0 ·

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

0 Likes 0 ·
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

0 Likes 0 ·
Show more comments
N6722C avatar image
N6722C answered N6722C edited

Hopefully

                 
  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 ?


10 |10000

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

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 19.1 MiB each and 23.8 MiB total.