script for my arcade

Ask gaming related questions (AHK v1.1 and older)
snax087
Posts: 4
Joined: 26 Jul 2021, 20:39

script for my arcade

Post by snax087 » 26 Jul 2021, 20:53

Hello. So i am completely green when it comes to AHK. Ive done a bit of research and have tried to create a simple script using the 'winactivate' command but that's about the extent of my abilities which is why i am reaching out for help. I have an arcade that friends play at a bar (windows pc running emulation software) and what is happening is there is about a 1 second window in between when certain emulators are executed from the front end software (the GUI from where you pick your game) and when the emulator window pulls up that if you hit a button in that 1 second window during the hand off from the front end GUI to the emulator running the game, the emulator window will not be in focus and will not accept your inputs, but the window will still be front and center and running. Thankfully you can still exit out of it without issue, but what i am needing guidance on is if there is a way to have an AHK script running that checks constantly or even just every 5-10 seconds if that specific emulator is running, it will bring it to the front so that the player doesnt have to exit out of the game and relaunch it.

So if they launch a game and hit a button by accident during that 1 second window not knowing that it will cause this problem, the script will be running silently in the background and say 'hey i see Retroarch.exe running and it's not the main window. I should fix that' so the window becomes the window in focus and will accept input from the player. Hopefully that makes sense :D any help would be appreciated. It's either try to get this working or install a button that is macro'd to Alt+Tab to give focus back to the game window. Thanks!
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: script for my arcade

Post by gregster » 27 Jul 2021, 04:10

Perhaps something like this - it's a loop, but it's mostly waiting for the emulator to be not the active window
(I assume there is only one matching window for ahk_exe Retroarch.exe - if not, you should add additional criteria identifying the target window ).

Code: Select all

Loop {  					
	WinWait, ahk_exe Retroarch.exe			
	WinWaitNotActive, ahk_exe Retroarch.exe	
	WinActivate, ahk_exe Retroarch.exe			
}

!Esc::ExitApp		; Alt + Esc
You could try it first with Notepad, ahk_exe Notepad.exe, to see how it's working.
Don't forget a hotkey that exits the script.
If the emulator runs with elevated rights, the script needs to do that, too.
snax087
Posts: 4
Joined: 26 Jul 2021, 20:39

Re: script for my arcade

Post by snax087 » 27 Jul 2021, 16:41

gregster wrote: Perhaps something like this - it's a loop, but it's mostly waiting for the emulator to be not the active window
(I assume there is only one matching window for ahk_exe Retroarch.exe - if not, you should add additional criteria identifying the target window ).

Code: Select all

Loop {  					
	WinWait, ahk_exe Retroarch.exe			
	WinWaitNotActive, ahk_exe Retroarch.exe	
	WinActivate, ahk_exe Retroarch.exe			
}

!Esc::ExitApp		; Alt + Esc
You could try it first with Notepad, ahk_exe Notepad.exe, to see how it's working.
Don't forget a hotkey that exits the script.
If the emulator runs with elevated rights, the script needs to do that, too.
It works absolutely perfectly! I tried to get it to lose focus any way i could or see if there were new problems the script might have introduced but nothing that i can see :D Thanks a lot man I really appreciate the help. This has been the one main flaw of this machine and now it seems like it's fixed. I figured it was probably an easy script that someone more fluent with AHK scripting could whip up for me. It doesnt seem to tax the cpu or memory at all either from what i can tell so thats a plus. Thanks again :dance: now to figure out the best way to get it to launch on bootup :think:
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: script for my arcade

Post by gregster » 27 Jul 2021, 16:51

Good to hear :thumbup: Yes, it should idle most of the time, until the window loses focus; and that should only be a short time.

snax087 wrote:
27 Jul 2021, 16:41
now to figure out the best way to get it to launch on bootup :think:
Have a look here: https://www.autohotkey.com/docs/FAQ.htm#Startup
snax087
Posts: 4
Joined: 26 Jul 2021, 20:39

Re: script for my arcade

Post by snax087 » 27 Jul 2021, 19:58

gregster wrote: Good to hear :thumbup: Yes, it should idle most of the time, until the window loses focus; and that should only be a short time.

snax087 wrote:
27 Jul 2021, 16:41
now to figure out the best way to get it to launch on bootup :think:
Have a look here: https://www.autohotkey.com/docs/FAQ.htm#Startup
Awesome. Im genuinely excited that i wont have to worry about people thinking my arcade doesnt work when this happened lol. Quick question though. If i have another emulator besides Retroarch running, can i tell it to look for another emulator/executable in addition to retroarch to look for? How would i format that in the script if thats possible? Or would i have to run a separate script for each executable?
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: script for my arcade

Post by gregster » 27 Jul 2021, 20:24

Well, only one window can be active at any time, so I assume that you are only running one emulator at a time.
For another emulator, I would run a separate script, with the same structure.

You could probably combine them, but it would get more complicated. I guess you could use a window group (https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_group), as long as only one emu is running - but I'd need to test it (which I can't do at the moment).
Post Reply

Return to “Gaming Help (v1)”