User avatar
stonstad
Topic Author
Posts: 263
Joined: 06 Jun 2016, 18:14
Location: United States
Contact:

Disambiguate Click Source

10 Nov 2021, 15:07

What is the preferred Noesis approach for disambiguating the source of a ButtonBase.Click event? i.e. keyboard, mouse, gamepad? One approach might be implementing KeyDown for keyboard/gamepad and MouseDown for mouse. I believe WPF has a mechanism to return the most recent interaction via InputManager.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Disambiguate Click Source

11 Nov 2021, 13:53

WPF provides the following:
if (InputManager.Current.MostRecentInputDevice is KeyboardDevice)
In Noesis there is no such API, so the only way would be to register to PreviewKeyDown, PreviewMouseDown and PreviewTouchDown to detect the latest device used. Could that work for you?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Disambiguate Click Source

11 Nov 2021, 14:10

Maybe we can provide that information through our View, something like this:
private void OnButtonClicked(object sender, RoutedEventArgs e)
{
  if (View.MostRecentInput == InputType.Mouse) { ... }
  else if (View.MostRecentInput == InputType.Keyboard) { ... }
}
I added a ticket in our bugtracker to think about it: #2185
 
User avatar
stonstad
Topic Author
Posts: 263
Joined: 06 Jun 2016, 18:14
Location: United States
Contact:

Re: Disambiguate Click Source

11 Nov 2021, 17:33

Thanks for the suggestion. I think this could work -- but I notice that I get Key.Space for gamepad events. This might be due to my Unity input mapping and I am unsure. I looked for a Unity gamepad input that returns "Space" and I didn't find any.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Disambiguate Click Source

12 Nov 2021, 16:00

I notice that I get Key.Space for gamepad events.
We internally convert gamepad actions to the corresponding keys so controls don't need to have specific code for gamepad, but you can access the source action in the OriginalKey property of the event args:
switch (k) {
  case Key_GamepadLeft: key = Key_Left; break;
  case Key_GamepadUp: key = Key_Up; break;
  case Key_GamepadRight: key = Key_Right; break;
  case Key_GamepadDown: key = Key_Down; break;
  case Key_GamepadAccept: key = Key_Space; break;
  case Key_GamepadCancel: key = Key_Escape; break;
  case Key_GamepadPageUp: key = Key_PageUp; break;
  case Key_GamepadPageDown: key = Key_PageDown; break;
  case Key_GamepadPageLeft: key = Key_PageLeft; break;
  case Key_GamepadPageRight: key = Key_PageRight; break;
  default: key = k; break;
}

Who is online

Users browsing this forum: No registered users and 4 guests