How to stop all mouse hover events in UMG at runtime.

Yes, what you’re describing is a common issue when dealing with mixed input methods (keyboard/mouse) in UI design. The mouse hover events can interfere with keyboard navigation if the cursor is at a position where it triggers hover events, even when you’re controlling the UI with the keyboard.

Solution: Disabling Hover Events on Key Press

The approach you mentioned — disabling the hover events when any key is pressed and enabling them again when the mouse moves — is definitely a feasible solution. Here’s a general idea of how you could implement it:

  1. Track Keyboard Input:

    • Set a flag (isKeyboardActive or similar) when any key is pressed. This flag will indicate that the user is navigating with the keyboard.
  2. Disable Hover Events:

    • Whenever isKeyboardActive is true, disable the hover events for all UI elements (buttons, settings, etc.). This can be done by preventing mouse events from being handled or by programmatically disabling hover effects on the elements.
  3. Enable Hover Events on Mouse Move:

    • Add a listener to detect mouse movement. Whenever the mouse moves, set isKeyboardActive to false and re-enable hover events.

Sample Implementation Outline (Pseudocode):

let isKeyboardActive = false;

// Disable hover events
function disableHoverEvents() {
    // Code to disable hover interactions on all UI elements
}

// Enable hover events
function enableHoverEvents() {
    // Code to enable hover interactions on all UI elements
}

// Event listener for key press
document.addEventListener('keydown', () => {
    isKeyboardActive = true;
    disableHoverEvents();
});

// Event listener for key release (optional, if needed)
document.addEventListener('keyup', () => {
    isKeyboardActive = false;
});

// Event listener for mouse movement
document.addEventListener('mousemove', () => {
    if (isKeyboardActive) {
        isKeyboardActive = false;
        enableHoverEvents();
    }
});

Alternative Approach: Use a UI State Management System

You can also implement a more robust state management system that tracks which input method (keyboard or mouse) is active at any given time. This would allow for more fine-grained control over UI interactions and would be easier to extend as your project grows.

  1. State Management:

    • Define states for input methods (e.g., keyboard and mouse).
    • Toggle the state based on user actions (key press or mouse move).
  2. Handle UI Interactions:

    • When in keyboard state, ignore hover events and allow keyboard navigation.
    • When in mouse state, handle hover events but ignore keyboard input.

This approach gives you more flexibility to easily manage different types of input.

Conclusion:

Both the direct approach (disabling hover events) and a more complex state-based approach can work, depending on the complexity of your project. The first solution is easier to implement and works for smaller projects, while the second approach would offer a more scalable and maintainable solution for larger applications.