Fix keyboard/arrow navigation not working when no UI element is focused

On Windows64 with KBM, moving the mouse over empty space (outside any
button) would clear the Iggy focus entirely. After that, pressing arrow
keys did nothing because Flash had no starting element to navigate from.

Two changes here:

- Don't set focus to IGGY_FOCUS_NULL when the mouse hovers over empty
  space. The previous hover target stays focused, so switching back to
  arrows keeps working seamlessly.

- When a navigation key is pressed and nothing is focused at all (e.g.
  mouse was already on empty space when the menu opened), grab the first
  focusable element instead of silently dropping the input. The keypress
  is consumed to avoid jumping two elements at once.

This makes mixed mouse+keyboard navigation feel a lot more natural.
You can point at a button, then continue with arrows, or just start
pressing arrows right away without having to hover first.
This commit is contained in:
MrTheShy 2026-03-05 23:44:48 +01:00
parent 05a27edc25
commit cb46908268
2 changed files with 20 additions and 1 deletions

View file

@ -846,7 +846,7 @@ void UIController::tickInput()
}
}
if (hitObject != currentFocus)
if (hitObject != IGGY_FOCUS_NULL && hitObject != currentFocus)
{
IggyPlayerSetFocusRS(movie, hitObject, 0);
}

View file

@ -900,6 +900,25 @@ void UIScene::sendInputToMovie(int key, bool repeat, bool pressed, bool released
app.DebugPrintf("UI WARNING: Ignoring input as game action does not translate to an Iggy keycode\n");
return;
}
#ifdef _WINDOWS64
// If a navigation key is pressed with no focused element, focus the first
// available one so arrow keys work even when the mouse is over empty space.
if(pressed && (iggyKeyCode == IGGY_KEYCODE_UP || iggyKeyCode == IGGY_KEYCODE_DOWN ||
iggyKeyCode == IGGY_KEYCODE_LEFT || iggyKeyCode == IGGY_KEYCODE_RIGHT))
{
IggyFocusHandle currentFocus = IGGY_FOCUS_NULL;
IggyFocusableObject focusables[64];
S32 numFocusables = 0;
IggyPlayerGetFocusableObjects(swf, &currentFocus, focusables, 64, &numFocusables);
if(currentFocus == IGGY_FOCUS_NULL && numFocusables > 0)
{
IggyPlayerSetFocusRS(swf, focusables[0].object, 0);
return;
}
}
#endif
IggyEvent keyEvent;
// 4J Stu - Keyloc is always standard as we don't care about shift/alt
IggyMakeEventKey( &keyEvent, pressed?IGGY_KEYEVENT_Down:IGGY_KEYEVENT_Up, (IggyKeycode)iggyKeyCode, IGGY_KEYLOC_Standard );