Disambiguate Click Source
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.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Disambiguate Click Source
WPF provides the following:
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?
Code: Select all
if (InputManager.Current.MostRecentInputDevice is KeyboardDevice)-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Disambiguate Click Source
Maybe we can provide that information through our View, something like this:
I added a ticket in our bugtracker to think about it: #2185
Code: Select all
private void OnButtonClicked(object sender, RoutedEventArgs e)
{
if (View.MostRecentInput == InputType.Mouse) { ... }
else if (View.MostRecentInput == InputType.Keyboard) { ... }
}Re: Disambiguate Click Source
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.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Disambiguate Click Source
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:I notice that I get Key.Space for gamepad events.
Code: Select all
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