Jump to content
(Public Beta) HyperSpin 2 is now available for everyone ×

Winactivate HS Script


Griff08

Recommended Posts

Posted

Good day all. I would like to seek help creating an autothotkey script (.ahk) that I can launch when HyperSpin Launches waits/sleeps for 20-30 seconds and then ensures that Windows is focused on my instance of Hyperspin.

Right now HS launches when Windows Launches and for some reason, I have a 50/50 chance that Windows will lose focus on HS and I will have to alt-tab to Hyperspin to get control of Hyperspin back.

I imagine the script would look something like:

sleep, 20000

winactivate HS

But as a noob script writer, I am not exactly sure how to implement this.

Posted
Good day all. I would like to seek help creating an autothotkey script (.ahk) that I can launch when HyperSpin Launches waits/sleeps for 20-30 seconds and then ensures that Windows is focused on my instance of Hyperspin.

Right now HS launches when Windows Launches and for some reason, I have a 50/50 chance that Windows will lose focus on HS and I will have to alt-tab to Hyperspin to get control of Hyperspin back.

I imagine the script would look something like:

sleep, 20000

winactivate HS

But as a noob script writer, I am not exactly sure how to implement this.

Yeah, that was the basis of what I started off doing. Well, long and short of it is: I read your request and then built a script around what it was you were trying to do. I created a script that verifies that HyperSpin is running. After verification is made that the application is running we then will bring it to the front. We will try a preset amount of times to bring it to the front before we consider it a failure. I hope that this script helps you out and is what you needed.

; Hyperspin On Top
; V. 1.0.4 - Rain
; As requested by Griff08
;
; This script will automatically check if Hyperspin is on top and activate it.
; If hyperspin cannot be found the script will automatically attempt a launch.
; You have three main variables that you need to assign. You will see these variables
; below.  The first is the time of delay (this is the amount of seconds that the
; script will ly in idle.  The second you need to point towards your HyperSpin
; installation.  The third variable you will need to set is the MaxFocusAttempts.
; This will tell the script how many times to attempt to bring HyperSpin to the
; front of the screen.

TimeOfDelay = 10				; How many seconds should we wait?
HSLocation = "H:\Hyperspin\HyperSpin.exe"	; The location of your HyperSpin executable.
MaxFocusAttempts = 5				; The maximum attempts to make focus.

;#####[THERE IS NO NEED TO EDIT ANYTHING BELOW THIS LINE!]#####;

; Now that your main variables have been set we can safely execute the following 
; script.  We will first declare a CurrentFocus variable to compare against the
; MaxFocusAttempts.  If that variable is equal to MaxFocusAttempts then something
; has went wrong (therefore we will abort out of the script with notification.

CurrentFocus = 0 		; Declare the CurrentFocus to 0

Sleep, TimeOfDelay * 1000 	; Get the delay time and multiply by 1000 = 1 second

; Begin Script

attemptLoad:

{
 if WinExist("HyperSpin")
 {
 	WinActivate		; Attempt to bring HyperSpin to the front.
 	ControlFocus, HyperSpin ; Collect focus from the HyperSpin application
 }
 else
 	Run %HSLocation%	; HyperSpin was not running, let's start it.
}

Sleep, TimeOfDelay * 1000	; Sleep for (5) seconds before verification.


CurrentFocus++			; Add 1 to the CurrentFocus value.
; If CurrentFocus is equal to our maximum attempts, let's exit out of here.
; this is done to prevent our script from creating a rouge loop.
if (CurrentFocus == MaxFocusAttempts)
{
   MsgBox, We were unable to load HyperSpin after %MaxFocusAttempts%.
   return			; Kills the script
}
; Now we will get the name of the formost window.  If it is equal to anything
; other than HyperSpin then we know we need to make attempt to reload HyperSpin
; to the front.
else
{
ControlGetFocus, OutputVar, HyperSpin	; Checks to formost window agains the HyperSpin name.
if ErrorLevel				; Is triggered if HyperSpin is not in the foreground.
	Goto, attemptLoad		; Return to our attemptLoad routine.

; If we have made it this far then we know that HyperSpin is running and at
; the foremost of the window.  This is the desired effect that we were looking
; for.  Now, we can exit the program knowing that our frontend is foremost.

else
   return	; Kills the script
}

return		; This is here to catch any mishaps that might have taken place.

; End Script

You can download this script from: http://ronharsh.com/scripts/HyperFocus.ahk

I really does hope this helps you. I have verified it about forty times before releasing it to the community. Thanks for your request!

Note: You can also edit this script, compile it and use it to launch your HyperSpin installation. In doing so it will be the one to initiate the HyperSpin process and monitor it while the initial launch has been made. I verified this on my arcade cabinet, and using it as a compiled EXE I executed and booted HyperSpin many times (and sometimes it would loose focus, but my script kept pulling it to the front!) Enjoy!

Please feel free to make request or give good/bad feedback about this script.

:hello:

Posted

Thank you so much rain! I really appreciate your help!

I will try this out right away!!! :)

I imagine myself launching this script when automatically windows starts ensuring a smooth load everytime :)

Thanks so much again!

Posted

I am glad that you like the script, and I hope that it works out well for you. I am farily new to AutoHotKey scripting ("coming from the world of C++/C#.") You will be happy to know that I am extinding this script to monitor HyperSpin throughout the loading process. So far I have a nice GUI setup for the application, complete with options and more. This will help users (like me) whom have an arcade cabinet and want their HyperSpin to always be on top.

Some of the benifits of this program I am creating is that after an emulator is exited it will verify that HyperSpin has returned to it's normal topmost location, it will verified that HyperSpin is still running and responsive (if it's not running my script will start HyperSpin, if it's not responsive my program will kill any running HyperSpin and reload the application.)

Thank you for your ideal, I never realized that I needed this until I saw your post. Oh, and by the way I do have a website that I am loading all of the scripts I have written to (about 220 for my cabinet.) I will post the link once the site is completed.

Also, I have given this script an official name finally! HyperTop!

Posted

This worked flawlessly. I can't thank you enough Rain.

I tried the script both as the launching source of HS and as a co-launch to HS.

Both ways worked without a hitch.

I am excited to see your advanced GUI based "HyperTop"

You are a gentleman and a scholar as well as a friend to travelers.

Thank you so much for your kindness.

Posted
that's a good script, but you could simplify it using WinWaitActive and a timeout handler. Of course if it ain't broke... Well, break it, fix it, and call it version 2.0 :P

Yeah, that's true - but at the time I was just designing that script purely for the gentlement above. I never suspected that anybody else would even be using it.

I am well aware as a professional computer programmer that loops should rarely (if ever be used.) But when you write a script in ten minutes on the tail end of your lunch break then loops suddenly become the way to go lol.

I am rewiring this script so that it is more "professional" and I am even working on a GUI for it (for the configurable options.) Someday whenever I finish getting my server online I will release it. Thank you for your post sir!

:bandit:

  • 1 month later...
Posted

I finally solved my problem!

In fact I usually speak French, so sorry if this is not understandable!

In this regard, is there a French section? otherwise it planned?

see you soon!

  • 6 months later...
  • 7 months later...
  • 2 weeks later...
  • 1 year later...
Posted

I can´t seem to get Rains old script to work here, anyone got a compiled working one or a similar script?

Hyperspin often drops to background after exiting emulators for me, I have tried the "restore frontend " settings in latest Hyperlaunch from github with no luck so a script like this might be a solution for me :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...