Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

  • 3 weeks later...

Hi when I launch supermodel from big box, I have no force feedback with my steering wheel. I've discovered this is because although the window is fullscreen and on top, it isn't actually active. If I alt tab it'll become active and the feedback will kick in. 

Is there a script that will make supermodel the active window? 

Link to comment
Share on other sites

  • 2 weeks later...
On 8/9/2023 at 3:25 PM, Frankie_Sambuca said:

Hi when I launch supermodel from big box, I have no force feedback with my steering wheel. I've discovered this is because although the window is fullscreen and on top, it isn't actually active. If I alt tab it'll become active and the feedback will kick in. 

Is there a script that will make supermodel the active window? 

I'm having the same issue, and I'd love to know a solution to making the window active automatically.

Link to comment
Share on other sites

On 8/9/2023 at 4:25 PM, Frankie_Sambuca said:

Is there a script that will make supermodel the active window? 

 

7 hours ago, NicoDirkfan said:

I'm having the same issue, and I'd love to know a solution to making the window active automatically.

 

that is an easy task. you will likely need just two lines. the first would wait for the window to exist. the second would activate the window. so you need the following:

WinWait https://www.autohotkey.com/docs/v1/lib/WinWait.htm

WinActivate https://www.autohotkey.com/docs/v1/lib/WinActivate.htm

 

if using title to determine window, then just insert title as the first parameter. title is case sensitive. change it accordingly

WinWait, Window Title Here
WinActivate, Window Title Here

 

and to be clear, there are several other ways to determine window, but the other common way is to determine via the executable. I don't know what this exe name is for the program, so this is just another example. you will need to insert proper exe file name

WinWait, ahk_exe exe-name-here.exe
WinActivate, ahk_exe exe-name-here.exe

 

 

 

if that doesn't work but you know a single ALT+TAB keypress does the trick then use this instead. Hmm I could have sworn this actually tabbed to the adjacent window in the tab list on my main PC but on my laptop this morning, this just seems to bring up the tab list for a split sec without actually tabbing to the next window....which if it works like that for you two that is a good thing (I think). Otherwise, you will only get this to work as long as there are no other windows existing. If you do have additional windows existing and it tabs to them, you could add additional {Tab down}{Tab up} cycles to tab back over the intended emulator's window

Send {LAlt down}{Tab down}{Tab up}{LAlt up}

For ex additional tab key presses, add as many as needed, if needed, depending on how many windows might exist. say you have a controller remap window also going at the same time and the first ALT+TAB makes that remapper window active, adding the 2nd cycle of tab down/up will then tab back to the emulator

Send {LAlt down}{Tab down}{Tab up}{Tab down}{Tab up}{LAlt up}

 

Link to comment
Share on other sites

On 8/23/2023 at 2:04 PM, skizzosjt said:

 

 

that is an easy task. you will likely need just two lines. the first would wait for the window to exist. the second would activate the window. so you need the following:

WinWait https://www.autohotkey.com/docs/v1/lib/WinWait.htm

WinActivate https://www.autohotkey.com/docs/v1/lib/WinActivate.htm

 

if using title to determine window, then just insert title as the first parameter. title is case sensitive. change it accordingly

WinWait, Window Title Here
WinActivate, Window Title Here

 

and to be clear, there are several other ways to determine window, but the other common way is to determine via the executable. I don't know what this exe name is for the program, so this is just another example. you will need to insert proper exe file name

WinWait, ahk_exe exe-name-here.exe
WinActivate, ahk_exe exe-name-here.exe

 

 

 

if that doesn't work but you know a single ALT+TAB keypress does the trick then use this instead. Hmm I could have sworn this actually tabbed to the adjacent window in the tab list on my main PC but on my laptop this morning, this just seems to bring up the tab list for a split sec without actually tabbing to the next window....which if it works like that for you two that is a good thing (I think). Otherwise, you will only get this to work as long as there are no other windows existing. If you do have additional windows existing and it tabs to them, you could add additional {Tab down}{Tab up} cycles to tab back over the intended emulator's window

Send {LAlt down}{Tab down}{Tab up}{LAlt up}

For ex additional tab key presses, add as many as needed, if needed, depending on how many windows might exist. say you have a controller remap window also going at the same time and the first ALT+TAB makes that remapper window active, adding the 2nd cycle of tab down/up will then tab back to the emulator

Send {LAlt down}{Tab down}{Tab up}{Tab down}{Tab up}{LAlt up}

 

Thanks for helping but that didn't seem to work. I tried both methods. The problem with Window Title is that it also shows the name of the game, for example "Supermodel - Scud Race" so just writing Supermodel didn't work. It also didn't work using the exe name either. For now I've just mapped two unused buttons on the wheel to Alt and Tab respectively and just cycle through the open windows back to Supermodel when I load each game. It's just clunkier than I'd like. Obviously launchbox is a very polished and pretty front end and doing that seems a bit out of place when everything else works so well. 

Link to comment
Share on other sites

On 8/28/2023 at 6:47 AM, Frankie_Sambuca said:

Thanks for helping but that didn't seem to work. I tried both methods. The problem with Window Title is that it also shows the name of the game, for example "Supermodel - Scud Race" so just writing Supermodel didn't work. It also didn't work using the exe name either. For now I've just mapped two unused buttons on the wheel to Alt and Tab respectively and just cycle through the open windows back to Supermodel when I load each game. It's just clunkier than I'd like. Obviously launchbox is a very polished and pretty front end and doing that seems a bit out of place when everything else works so well. 

 

I recently got familiar with the emulator. Do note I did have to use partial match mode for window title match to work. I didn't initially realize the title would change based on the game running so it's understandable why the standard WinTitle method didn't work for you following my advice. This below will mean if you had a line like "WinWait, Supermodel" it will only need to find "Supermodel" in the title. It is still case sensitive, but again, just a partial match is required and this creates a match with something like "Supermodel - Scud Race"

SetTitleMatchMode, 2

 

If you're content with your button method that is OK, but wanted to let you know every method I described, window title, executable name, and sending keys, worked for me as expected. so if you really want it automated I can try and help you figure it out.

Link to comment
Share on other sites

1 hour ago, skizzosjt said:

 

I recently got familiar with the emulator. Do note I did have to use partial match mode for window title match to work. I didn't initially realize the title would change based on the game running so it's understandable why the standard WinTitle method didn't work for you following my advice. This below will mean if you had a line like "WinWait, Supermodel" it will only need to find "Supermodel" in the title. It is still case sensitive, but again, just a partial match is required and this creates a match with something like "Supermodel - Scud Race"

SetTitleMatchMode, 2

 

If you're content with your button method that is OK, but wanted to let you know every method I described, window title, executable name, and sending keys, worked for me as expected. so if you really want it automated I can try and help you figure it out.

So the complete script would be,

SetTitleMatchMode, 2

WinWait, Supermodel

WinActivate, Supermodel

I get by with my button method purely because it stops me needing a keyboard but I'd much rather it was automated, I'll give it a go in a bit and let you know how I get on.

Just to be clear I just type the script into the running script for the emulator exactly as I wrote it above?

 

Link to comment
Share on other sites

2 hours ago, skizzosjt said:

 

I recently got familiar with the emulator. Do note I did have to use partial match mode for window title match to work. I didn't initially realize the title would change based on the game running so it's understandable why the standard WinTitle method didn't work for you following my advice. This below will mean if you had a line like "WinWait, Supermodel" it will only need to find "Supermodel" in the title. It is still case sensitive, but again, just a partial match is required and this creates a match with something like "Supermodel - Scud Race"

SetTitleMatchMode, 2

 

If you're content with your button method that is OK, but wanted to let you know every method I described, window title, executable name, and sending keys, worked for me as expected. so if you really want it automated I can try and help you figure it out.

So it still doesn't seem to work. The only thing I've not mentioned is that for that emulator I use a program called QRES as an additional app. All it does is switch the refresh rate to 57hz to match the original hardware and then back to 60hz when you quit the emulator. I dont think this will have any effect on the autohotkey script but I thought I'd just mention it. 

Link to comment
Share on other sites

1 hour ago, Frankie_Sambuca said:

So the complete script would be,

SetTitleMatchMode, 2

WinWait, Supermodel

WinActivate, Supermodel

I get by with my button method purely because it stops me needing a keyboard but I'd much rather it was automated, I'll give it a go in a bit and let you know how I get on.

Just to be clear I just type the script into the running script for the emulator exactly as I wrote it above?

 

I'm thinking due to the specific issue you're having, that being the window is on top but not active,  the WinActivate command might not help you out. I'm not capable of recreating the issue you have so all I am going by is if the windows I'm manipulating are getting moved around and the script does do that. With that said, I would do the ALT+TAB keys getting sent because it would be better at selecting the specific window, the emulator and making sure it's in focus so your wheel feedback works.

 

So yea try this below. You're correct that it should go in "Running Script" field of the emulator

SetTitleMatchMode, 2
WinWait, Supermodel
Sleep, 3000
Send {LAlt down}{Tab down}{Tab up}{Tab down}{Tab up}{LAlt up}
SoundBeep

image.thumb.png.043e91ddcd66a0c3843c508e670b4542.png

This does two tab key presses, remove the 2nd cycle if you only need one cycle or add more if you need more. That is dependent on how many windows you have open when you launch the game. The SoundBeep is there so you should actually hear a beep, which means the script ran fine since it is the last line. It can be removed after testing. Maybe the sleep line which pauses the script for 3secs may also help, making sure windows have had time to actually display. You can change the timing if needed.

 

49 minutes ago, Frankie_Sambuca said:

So it still doesn't seem to work. The only thing I've not mentioned is that for that emulator I use a program called QRES as an additional app. All it does is switch the refresh rate to 57hz to match the original hardware and then back to 60hz when you quit the emulator. I dont think this will have any effect on the autohotkey script but I thought I'd just mention it. 

hmmm, yea I'd say prolly not either. if it creates a window that can be ALT+TAB'd to then this would count as one of the windows you need to consider in how many times you need to press tab though

Link to comment
Share on other sites

12 hours ago, skizzosjt said:

I'm thinking due to the specific issue you're having, that being the window is on top but not active,  the WinActivate command might not help you out. I'm not capable of recreating the issue you have so all I am going by is if the windows I'm manipulating are getting moved around and the script does do that. With that said, I would do the ALT+TAB keys getting sent because it would be better at selecting the specific window, the emulator and making sure it's in focus so your wheel feedback works.

 

So yea try this below. You're correct that it should go in "Running Script" field of the emulator

SetTitleMatchMode, 2
WinWait, Supermodel
Sleep, 3000
Send {LAlt down}{Tab down}{Tab up}{Tab down}{Tab up}{LAlt up}
SoundBeep

image.thumb.png.043e91ddcd66a0c3843c508e670b4542.png

This does two tab key presses, remove the 2nd cycle if you only need one cycle or add more if you need more. That is dependent on how many windows you have open when you launch the game. The SoundBeep is there so you should actually hear a beep, which means the script ran fine since it is the last line. It can be removed after testing. Maybe the sleep line which pauses the script for 3secs may also help, making sure windows have had time to actually display. You can change the timing if needed.

 

hmmm, yea I'd say prolly not either. if it creates a window that can be ALT+TAB'd to then this would count as one of the windows you need to consider in how many times you need to press tab though

That one worked! I did have to fiddle with the startup/shutdown screen timings as it was switching screens while the game over screen was displayed but once I got that right it worked like a charm! Thankyou so much!!

  • Game On 1
Link to comment
Share on other sites

Hi all,

Noob here.

I was wondering if there is a script so an emulator can be closed using an Xbox contoller instead of a keyboard, such as you can when using Retroarch?

I'm trying to make my setup as user friendly as possible and don't want a mouse and keyboard attached.

Thanks in advance.

Link to comment
Share on other sites

16 minutes ago, tbergman said:

Hi all,

Noob here.

I was wondering if there is a script so an emulator can be closed using an Xbox contoller instead of a keyboard, such as you can when using Retroarch?

I'm trying to make my setup as user friendly as possible and don't want a mouse and keyboard attached.

Thanks in advance.

Do not need a script. Just bind your controller buttons in LB/BB. LB/BB will exit many emulators using an Xbox controller easily. In LB bind to the option for "Exit Game" and it can be a 2 button combo. In BB bind for the option listed as "Close Active Window". BB has the option to bind for a 2 button combo as well. 

Link to comment
Share on other sites

  • 2 weeks later...

All,

I am at my wits end and have an issue similar to someone on page 51 or 52. I have tried everything I can think of to get my script to work but no such luck.

What I am trying to accomplish. When I start MK11 in LB it fires up an ahk script to open KeyboardSplitter.exe, then navigates to games in KeyboardSplitters window (this can be accomplished by hitting Alt + Right 4 times + Down+ Right + Down + Enter...literally the same thing from page 51,52. 

I tried copying the script @skizzosjt helped document (just to see it in action), pasted in a new AHK file, saved it as test.ahk, then went into ahk2.exe and converted it. When I ran it the script sure enough I could see quick flashing across File, Home, Share, View in the window. I then thought, and went to chatgpt to see what the command was to open KeyboardSplitter.exe, took that information and pasted it before the original "test" script language thinking this has to work. When I saved/converted it and opened the new AHK file ahk2exe spit out it opened KeyboardSplitter.exe but then nothing else after that. I have tried roughly 10 different iterations and I am completely stuck. Below is my current script (no I have not got to the exit part yet as I have been focusing on getting the main part to work first

 

Run, C:\Keyboard Splitter\KeyboardSplitter.exe

SetKeyDelay, 100

Sleep, 3000

Send {Alt}
Send {Right 4}
Send {Down}
Send {Right}
Send {Down}
Send {Enter}
Sleep, 3000
Send, {Tab}
Send {Enter}

Link to comment
Share on other sites

14 hours ago, OldSkool8bit said:

All,

I am at my wits end and have an issue similar to someone on page 51 or 52. I have tried everything I can think of to get my script to work but no such luck.

What I am trying to accomplish. When I start MK11 in LB it fires up an ahk script to open KeyboardSplitter.exe, then navigates to games in KeyboardSplitters window (this can be accomplished by hitting Alt + Right 4 times + Down+ Right + Down + Enter...literally the same thing from page 51,52. 

I tried copying the script @skizzosjt helped document (just to see it in action), pasted in a new AHK file, saved it as test.ahk, then went into ahk2.exe and converted it. When I ran it the script sure enough I could see quick flashing across File, Home, Share, View in the window. I then thought, and went to chatgpt to see what the command was to open KeyboardSplitter.exe, took that information and pasted it before the original "test" script language thinking this has to work. When I saved/converted it and opened the new AHK file ahk2exe spit out it opened KeyboardSplitter.exe but then nothing else after that. I have tried roughly 10 different iterations and I am completely stuck. Below is my current script (no I have not got to the exit part yet as I have been focusing on getting the main part to work first

 

Run, C:\Keyboard Splitter\KeyboardSplitter.exe

SetKeyDelay, 100

Sleep, 3000

Send {Alt}
Send {Right 4}
Send {Down}
Send {Right}
Send {Down}
Send {Enter}
Sleep, 3000
Send, {Tab}
Send {Enter}

 

not being one who likes to take credit when it's not warranted, I think you meant JoeViking245. maybe I had some input trying to help Cnells2000 in that conversation, but Joe provided that script I think you're referring to.

 

I think you are over thinking or over complicating things. I've seen youtube videos in the past with folks using LED Blinky and setting up MK11 using virtual controllers.

I only mention LED Blinky because I see your other thread that looks like asking for similar help.

I've only ever played the MK games with controllers. But I've caught in passing from said youtube videos some of them are finicky such as they only accept a single player to utilize the keyboard as input so it forces the 2nd player to utilize a controller...or at least that sounds like how the devs designed it from their perspective.

Going back to virtual controllers. The game just plain works better when receiving xinput I imagine. You still got hoops to jump through, but my approach to this would be to use virtualized xinput controllers. ie your dinput encoder detects P1B1 is pressed and then sends Left Control for ex. you would then have a remapper program that sees that Left Control button being sent and transposes it to virtualized xinput controller #1 "A" button. This means in the end it would be like pushing that button on your cabinet would be the same to the game as if an Xbox controller was physically plugged in.

So if I understand your setup right LED Blinky should work fine because you are still using your encoder in dinput but those keys are being transposed to xinput for the game. You might think it's just more of the "same difference" by using this keyboard splitter program but I cannot provide much help or advice for it since I am not familiar with the software beyond its basic use case/intent.

 

What you're doing is a little "janky" to me since you would see that program on the screen and moving tabs or windows around. It won't look like clean launch in other words. There must be an easier way to tell it to load a profile of some sort but there is again only so much help I can provide not knowing that program.

I strongly suggest to use some remapper that can see keyboard input and transpose to xinput. I'm a fan of virtualcontroller and have a relatively detailed set of instructions on basic use/setup here (link below). there are of course more programs out there that do the same, but this is my go to program for this need. take notice the link to download the program has it titled as "vjoy-controller" but it's really known as virtualcontroller. I can provide advice on how to utilize this program by comparison, so why I recommend trying a different approach with said different program. These instructions also detail how to utilize AHK to automate running the program and loading the specific profile, all while doing it out of eye sight behind the scenes!

https://forums.launchbox-app.com/topic/74291-how-do-i-close-an-additional-app-ucr-after-a-game-quits/?do=findComment&comment=439313

 

  • Like 1
Link to comment
Share on other sites

@skizzosjt @JoeViking245

I appreciate the feedback. MK11 and my other games actually do run really well with the keyboard splitter if you ever wanted to try it out, but will check out what you suggested as well. As you can guess I wont really have a KB readily accessible but rather joysticks and buttons mapped to various keys, hence the ahk. I have been messing around with many different variations in the script and am getting closer (i.e. can now get everything to load properly and pull up/run the game) but have run into a wall with getting the program (Keyboard Splitter) to quit after the game's .exe file has stopped running. I have tried reading through some of the .exe stuff but am just lost. Here is what I have so far (In AHK V2 if that matters)...what I am now stumpped on is in red at the bottom

SetKeyDelay 200                                    

Run("C:\Keyboard Splitter\KeyboardSplitter.exe") 

Sleep 4000

Send("{Alt}")

Send("{Right 4}")

Send("{Down}")

Sleep 1000

Send("{Right}")

Sleep 1000

Send("{Down}")

Send("{Enter}")

Sleep 2000

Send("{Tab}")

Send("{Enter}") ; --------------------------this right here is where the game mk11.exe launches and script is good up to this point

SetTitleMatchMode 2 ; Allow for partial window title matching ; --------------------this is where I am trying to have a loop to check if mk11.exe is running and if not then hit Tab, then                                                                                                                                            Enter, then F4 to close out of keyboard splitter

Loop
{
    If not WinExist("Mortal Kombat 11")
    {
        ; Replace "Mortal Kombat 11" with the actual window title of MK11.exe
        ; If the title of the game window is different, you should change it here.
        ; This line checks if MK11 is not running.
        ExitApp
    }
    Sleep 5000 ; Check every 5 seconds (adjust as needed)
}

Sleep 2000

Send("{Tab}")

Send("{Enter}")

Send ("!{F4}")

Link to comment
Share on other sites

1 hour ago, OldSkool8bit said:

what I am now stumpped on is in red at the bottom

I've never seen the syntax Send ("!{F4}") (vs Send !{F4}).  Maybe it's a 2.0 thing.  Since it seems to work for you, I'll leave it like that.

 

.....
.....
Send("{Enter}") ; ---------------------this right here is where the game mk11.exe launches and script is good up to this point


Process, Wait, mk11.exe                ;wait until mk11.exe is running
While WinExist("ahk_exe mk11.exe")
   sleep 700

Sleep 2000                            ;not sure this is needed unless after exiting, KS takes a couple secs to pop up
Send("{Tab}")
Send("{Enter}")
Send ("!{F4}")

You had in your loop that if mk11 doesn't exist, exitapp.  If mk11 takes a second (or more) to load after 'pressing Enter' your app will exit.  Never closing keyboard splitter.

So instead, after 'pressing Enter', wait until it is active, then hang out until it closes (aka: you exit the game).  THEN Tab, Enter Alt+F4.

Instead of Sleep 2000, you might be able to use something like WinWaitActive, ahk_exe keyboardsplitter.exe (or whatever KS's exe file is called).  So if it takes 500ms, it'll continue right away.  Instead of waiting the full 2 seconds.

Hope that helps (and works, as I didn't test it ;)). 

 

Edit:  You could also eliminate the last 4 lines altogether.  Instead of 'navigating' through the UI, just close the app.

WinClose, ahk_exe keyboardsplitter.exe  (or whatever KS's exe file is called).

Edited by JoeViking245
afterthought
Link to comment
Share on other sites

5 minutes ago, OldSkool8bit said:

@skizzosjt @JoeViking245

 

Also forgot to mention I have the window names since I can hold alt tab on the keyboard I'm using to set all this up if that helps or would make it easier than using the games .exe name

That's too volatile.  Because you never know what may pop up in between. ('Do I have to Alt+Tab once? Or 2 times?')  Using game.exe eliminates most (if not all) issues.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...