Page 1 of 1
Disambiguate Click Source
Posted: 10 Nov 2021, 15:07
by stonstad
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.
Re: Disambiguate Click Source
Posted: 11 Nov 2021, 13:53
by sfernandez
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?
Re: Disambiguate Click Source
Posted: 11 Nov 2021, 14:10
by sfernandez
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
Re: Disambiguate Click Source
Posted: 11 Nov 2021, 17:33
by stonstad
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.
Re: Disambiguate Click Source
Posted: 12 Nov 2021, 16:00
by sfernandez
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;
}