Rocko Bonaparte
Topic Author
Posts: 39
Joined: 13 Oct 2020, 08:32

Firing commands from keyboard/gamepad

13 Jan 2021, 08:12

I have some buttons that have commands associated with them. These commands run fine when clicking on them with a mouse. Now I'm trying to integrate a keyboard and a gamepad. I'm not using Unity's InputManager (I'm using InControl) so I have to manually toggle KeyDown/KeyUp in Noesis' API. For navigation (up/down in particular) this has been working fine. I also see my GuiSubmit action trying to do the same with the GamepadAccept (it does call KeyDown and eventually KeyUp in another frame) but that doesn't seem to fire the button's command.

I'm assuming GamepadAccept is the key I want to use and will send a command to the selected/highlighted button. My WPF standalone build doesn't seem to fire the command itself from a keyboard, which makes me think my approach is wrong. I wanted to check if there's anything in particular I need to do in Unitywith Noesis to have GuiAccept invoke a control's command, or if there's a different approach I am supposed to take.
 
Rocko Bonaparte
Topic Author
Posts: 39
Joined: 13 Oct 2020, 08:32

Re: Firing commands from keyboard/gamepad

14 Jan 2021, 08:18

So, uh, I did some stuff. I figured I might as well more explicitly capture key events in my listview and this seemed to give me keyboard control in a standalone application. In particular, I created a handler for ListView.PreviewKeyDown. I moved that over the Unity and Noesis, which meant doing the ConnectEvent ritual so that Noesis knew about the event handler. This gave me something that responded to the keyboard in hilarious ways.

The good: I could hit my game's 'use' button binding, it would pass it along to a KeyDown on GamepadAccept, and this would work its way to the control to select the button! Yay!
The bad: Spacebar would also toggle buttons even though this wasn't given as GamepadAccept in bindings to InControl. So it looks like Noesis is grabbing the input manager by itself and listening for that spacebar. Is there a way I can shut that off? I am pretty sure InControl and the legacy input manager don't play well together and I'd rather manually strobe Noesis' key events myself using KeyDown() and KeyUp() calls.
The ugly: My GamepadAccept KeyDown() was being interpreted by my PreviewKeyDown handler as a spacebar! When I saw it come in the first time, I said out loud, "Watcha' doing, Noesis?" It was really suspicious that space bar would come rolling in the moment I pressed my use button (E key for testing) and I eventually correlated that it was turning GamepadAccept into Key.Space. I'm ... really perplexed by this and I'm not really sure what I want to think about this. I have yet to try this with an XboxOne controller to see happens.

So it's fair to say I have made some progress but that progress has been very odd.

Another fun thing: well before this event handler existed as a concept in the universe, I discovered I could somehow hit my up key and the use key for the top-most element and this would somehow toggle the command for the button. It would only work for the topmost one. This is a completely bizarre mystery to me. So this would translate to Noesis being given a KeyDown() for Up and a KeyDown() for GamepadAccept before getting a KeyUp() for either of them. I just thought that was interesting.
 
Rocko Bonaparte
Topic Author
Posts: 39
Joined: 13 Oct 2020, 08:32

Re: Firing commands from keyboard/gamepad

16 Jan 2021, 01:21

I figured out that I can disable Noesis' Unity input scanning by setting EnableKeyboard and EnableGamepad to false in my NoesisView MonoBehaviour so I can at least suppress actual space bars. I had it confirmed by somebody else that using the PreviewKeyDown is a normal and correct way to get those key events in a regular WPF application, so I guess that maps out. So I'm just treating the spacebar key that rolls in as a peculiar translation for the sake of .NET compatibility. I just bathe the event handler code in a paragraph of commentary so I don't forget.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Firing commands from keyboard/gamepad

18 Jan 2021, 11:30

The creators of InControl had an integration for NoesisGUI, I don't know if it is still mantained and updated: http://www.gallantgames.com/pages/incontrol-noesis-gui
I'm assuming GamepadAccept is the key I want to use and will send a command to the selected/highlighted button. My WPF standalone build doesn't seem to fire the command itself from a keyboard, which makes me think my approach is wrong.
Yes, that key is used to fire buttons, but it will only fire the Click event and associated command if the Button has focus, as key events are raised from the focused element. Maybe your problem was related to focus and not the key itself.
I wanted to check if there's anything in particular I need to do in Unitywith Noesis to have GuiAccept invoke a control's command, or if there's a different approach I am supposed to take.
There is nothing in particular, if you take a look at our Buttons sample, and the code in NoesisView for the input, you will see we just inject Key.GamepadAccept when using gamepad.
Spacebar would also toggle buttons even though this wasn't given as GamepadAccept in bindings to InControl. So it looks like Noesis is grabbing the input manager by itself and listening for that spacebar. Is there a way I can shut that off? I am pretty sure InControl and the legacy input manager don't play well together and I'd rather manually strobe Noesis' key events myself using KeyDown() and KeyUp() calls.
As you already found there is an option in NoesisView component to disable keyboard input, so you can handle everything yourself from InControl.
My GamepadAccept KeyDown() was being interpreted by my PreviewKeyDown handler as a spacebar!
Gamepad buttons are translated to keyboard keys in Noesis so controls can share the same implementation for keyboard and gamepad/remote. Anyway, the original button can always be obtained from KeyEventArgs in the OriginalKey member.
Another fun thing: well before this event handler existed as a concept in the universe, I discovered I could somehow hit my up key and the use key for the top-most element and this would somehow toggle the command for the button. It would only work for the topmost one. This is a completely bizarre mystery to me. So this would translate to Noesis being given a KeyDown() for Up and a KeyDown() for GamepadAccept before getting a KeyUp() for either of them. I just thought that was interesting.
How is KeyboardNavigation.DirectionalNavigationMode configured in your panel? As I said before all keyboard events are raised from the focused element, so it is important to make sure focus is moving to the correct control. But it is very strange that the Click only worked when both Up and Accept where pressed, there is no such logic implemeted in the button.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 84 guests