oomek/attractplus

AM retains focus if keys pressed during game launch

Closed this issue · 5 comments

Steps to reproduce (for Mame):

  1. Launch game
  2. Immediately spam (press+release) "right-arrow" (could be any key/keys)
  3. AM retains focus instead of Mame (usually 1 in 5 attempts hits the issue)

Occurs in window & full-screen modes (AM+ 3.0.7, Win10 Pro)
In window mode, AM shows a black screen but retains focus (blue border), while Mame loads with an orange flashing taskbar item (ie: wants attention). Mame must be re-focused to continue (alt+tab / mouse-click).

Emulator Option: Non-Blocking Mode Wait = 2 seconds
Same steps to reproduce. However after the wait time AM now thinks it's back in control and will display the layout, with un-focused Mame still running in the background. Launching again will create another instance of Mame.

There's likely a dozen different scripts to ensure apps remain focused, but it would be super-nice if this worked out-of-the-box. Kids push buttons, and guests practice fireballs!

Thanks for your reports. I'll look into all your opened issues once I'm done with Async Loader branch.

oomek commented

After thorough investigation we've concluded that this issue is more complex and system specific. It needs further tests.
From what we've observed it can be divided into two groups: window focus and window priority issues.

On my system Windows 11 all combinations of AM window modes: Fill Screen, Fullscreen, Window work with no issues when mame is launched in Full Screen and the keyboard key is held or repeatedly pressed.

When mame is launched in Windowed mode and the keyboard key is held, mame's window priority is underneath AM and it has no focus.

oomek commented

Things I've tried:
BlockInput( true/false ) before and after CreateProcessW() - no change
Setting various CreateProcessW() flags - no change
Finding a HWND of the emulator window and then setting the focus and priority after a delay - partially worked, caused desktop flashes on exiting the emulator.

This issue is likely related to Antivirus software, specifically those with Application Firewalls.

When AM launches Mame the firewall intercepts it to verify it's safe before handing over control - this happens in a matter of milliseconds and is normally invisible to the user.

However, if you happen to be spamming keys during this process there's a chance a keypress will slip between the launch and the handover - this re-focuses AM (which is ignoring inputs until the app has exited). Mame then appears on top but without focus, requiring (alt+tab / mouse-click) to regain control.

This is my working theory now since I could not replicate the issue on my second machine, which is NOT running an Application Firewall.

oomek commented

Closing for now