Switching Between Mouse and Keyboard in Menu

samspade

Member
Lets say you have a menu system which supports keyboard/gamepad and/or mouse and allows you to select things with either. How would you handle switching between the various input types? This is not about code but about the actual practice of what would make the most sense.

For example, how would you handle the following situations to show which button the player is currently selecting?
  • Mouse is hovering over one option and the player then starts using the keyboard to select things? Does the mouse deactive immediately or after a moment? Does the keyboard selection override the mouses selection?
  • Player has been using the keyboard but now switches to the mouse. Does the option selected with the keyboard immediately de-select or do you wait for the mouse to be over another choice?
 

NightFrost

Member
  • Mouse is hovering over one option and the player then starts using the keyboard to select things? Does the mouse deactive immediately or after a moment? Does the keyboard selection override the mouses selection?
The way I've set my UI system to handle this: as soon as player uses keyboard to select another menu option, the element mouse hovers over deselects and selection moves to whatever element the keyboard control dictates as new focus. The keyboard selection overrides mouse because it is the latest action. If mouse gets moved, it is again the latest action and overrides previous selection. It doesn't matter if keyboard or mouse is the source of the previous selection, new selection always overrides previous one; it cares not what made the selection. (The mouse does not "deactivate" but both keyboard and mouse actions are checked in parallel and acted upon whenever some activity is detected.)
  • Player has been using the keyboard but now switches to the mouse. Does the option selected with the keyboard immediately de-select or do you wait for the mouse to be over another choice?
A soon as mouse moves, it becomes the latest action and will override previous selection. If it hovers over nothing, the UI system sees it as selecting nothing and the previous selection (made with keyboard, but that is not relevant) gets deselected. If it hovers overs some UI element, that gets selected.

It should be noted that my system always defines a default selection, a UI element that is selected by default when UI system starts running. This serves as starting navigation point for keyboard-controlled selections. It also has the ability to recall what was the last selected element when mouse motion has deselected it. This way, when you move mouse away from an element and it deselects, and you then use keyboard controls to try to select something, the navigation code notices nothing is selected and makes the last selection as current selection again.

Running mouse and keyboard selection at the same time can be a little tricky, but I've noticed it comes much easier when the code checks for mouse hovers only if the mouse has moved during current step. If it hasn't, hover checks will be skipped. This has the most direct effect of allowing free keyboard navigation even while mouse if hovering over a selection. (There's also certain UI elements, chiefly sliders, that must be capable of locking the system into hover-over mode so the element remains active as long as button is pressed down, no matter where the pointer moves.)
 
Top