Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

8 hours ago, skizzosjt said:

could be because you used a generic "Ctrl" key instead of specifying which one. Try using the same script but use "LCtrl" instead. Also do not capitalize "C" due to it would imply sending a capitalized C which requires also hitting the shift key. So I believe what your script is actually sending is more like "Ctrl, SHIFT, C" and that alone might make the Citra hotkey not work.

AHK is weird here, it doesn't matter if the letter is capital or not if it's a hotkey. ie if you make two hotkeys like so, both of these would work the same, exiting the script

A::ExitApp

a::ExitApp

Both of those hotkeys would trigger with the "a" or "A" key press, as in whether or not you hold the shift key. So using "a" or "A" is interchangeable in the context of a hotkey. Lowercase/uppercase doesn't matter

But when a letter is in the send command it is case sensitive as I described above.

That did it, thank you! Had no idea it was case sensitive.

  • Like 1
Link to comment
Share on other sites

On 5/3/2023 at 1:13 PM, skizzosjt said:

 

I also have another problem with an emulator in the pause menu. You know A7800? It's a fork of MAME for Atari 7800 games and I would have thought it used the same F7 and F8 as load/save keys, but it's F6 and F7 instead. Sounds like an easy fix but it doesn't do anything when I select the option in the pause menu. Seems some emulators don't recognise the same scripts, even when one is the fork of the other. Would you have any idea of the solution? Thanks again.

Link to comment
Share on other sites

  • 5 weeks later...

Hey Everyone. I Have A Program Im Trying to use with a script. it set up to boot like i need it to but the rest has to be done by script. i have a video below of exactly how it can be done, i just dont know how to make the script. could someone help me with a script for this please? Much appreciated.

 

The Script Is Wait Like 2 Seconds....Alt Key, Right, Right, Right, Right, Down, Right, Down, Enter Key  Wait Like 1.5 Secs....Tab, Enter Key.  (The game will load like normal. Wait till im done playing. when i exit the game, Send the Tab Key, Enter Key. And Finally Alt+F4 to close. Done.

 

Any Help Will Be Appreciated. This program has no hotkeys, Hence why im trying to do this. thanks guys.

 

 

Edited by Cnells2000
Fixed Video Correctly.
Link to comment
Share on other sites

couple hours later....

I started looking for solutions everyhere and came across this after using Chatgpt.

it game me a script and i added a couple things and it got really close!!! holy $#@! Skynet is getting scary!!

It gave me:

; Wait for 3 seconds
Sleep 3000

; Send Alt key
Send {Alt}
Sleep 100

; Send Right arrow key (4 times)
Send {Right}
Sleep 100
Send {Right}
Sleep 100
Send {Right}
Sleep 100
Send {Right}
Sleep 100

; Send Down arrow key
Send {Down}
Sleep 100

; Send Right arrow key
Send {Right}
Sleep 100

; Send Down arrow key
Send {Down}
Sleep 100

; Send Enter key
Send {Enter}
Sleep 100

; Wait for 3 seconds
Sleep 3000

; Send Tab key
Send {Tab}
Sleep 100

; Send Enter key
Send {Enter}
Sleep 100

SetTitleMatchMode, 2                                                           ----------------I ADDED THIS AREA

; Wait for the "tmnt.exe" window to become active
WinWaitActive, tmnt.exe

; Wait until the process closes
Process, WaitClose, tmnt.exe
Sleep 100                                                                                ----------------PART I ADDED ENDS HERE

Send {Tab}
Sleep 100

; Send Enter key
Send {Enter}
Sleep 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

ExitApp

 

This is the Result:

 

 

 

It Seems to Go all the way through to 00:26 then it stops.....it needs to finish this part. the script is still open on the bottom right so its not finished somewhere....

Its supposed to finish these steps.....

 

Send {Tab}
Sleep 100

; Send Enter key
Send {Enter}
Sleep 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

ExitApp

 

Its nearly there!! can someone please help me finish this?

 

 

Edited by Cnells2000
added result and video
Link to comment
Share on other sites

14 hours ago, Cnells2000 said:

Its supposed to finish these steps.....

Try giving tmnt more time to [fully] close. (1 [FULL] second? 2 seconds?)

Is it safe to assume that 'Send {Tab}' is to set focus on "OK" (then 'Send {Enter}' to select it)?

 

SetKeyDelay, 100

Sleep, 3000

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

; Wait for the "tmnt.exe" window to become active
WinWaitActive, ahk_exe tmnt.exe

; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep 1000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, JoeViking245 said:

Try giving tmnt more time to [fully] close. (1 [FULL] second? 2 seconds?)

Is it safe to assume that 'Send {Tab}' is to set focus on "OK" (then 'Send {Enter}' to select it)?

 

SetKeyDelay, 100
SetTitleMatchMode, 2

Sleep, 3000

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

; Wait for the "tmnt.exe" window to become active
WinWaitActive, tmnt.exe

; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep 1000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

 

 

@JoeViking245 Script results: i changed the 1000 to 3000 to give it more time. didnt know if i needed to add a comma to the sleep 1000 and sleep 2000 so i made a script with the commas and without.

 

 

the window is highlighted after exiting game on your script video and mine and i can manually push the tab key and make it move to ok, the script isn't just doing it yet. still stopping at same area.

Link to comment
Share on other sites

On 5/27/2023 at 9:37 PM, Madhead said:

I also have another problem with an emulator in the pause menu. You know A7800? It's a fork of MAME for Atari 7800 games and I would have thought it used the same F7 and F8 as load/save keys, but it's F6 and F7 instead. Sounds like an easy fix but it doesn't do anything when I select the option in the pause menu. Seems some emulators don't recognise the same scripts, even when one is the fork of the other. Would you have any idea of the solution? Thanks again.

sorry for missing this initially. I dont emulate that system or use said emulator. Sounds more like the emulator itself has different keys assigned. if emulator A has keys save/load F7 and F8, but emulator B has save/load keys F6 and F7 and you want them something different then change that in the emulators settings. if not available in the emulator's settings you could use AHK to create a hotkey to change them. just make a simple one line hotkey like F7::F6 and on next line F8::F7 or whatever you need and put that in the emulators running script if that is the route you need to take. 

 

 

This line is messing things up for you

12 hours ago, Cnells2000 said:

WinWaitActive, tmnt.exe

The WinWaitActive line I quoted above is not doing what you think it is due to you did not define a window that will ever exist. Due to that your script will pause at this line indefinitely. As it reads right now, that line is saying "wait here until a window with a title of "tmnt.exe" exists". I know that game's window is not titled as such. You provided the executable name instead....but if you use the exe name you need to use the proper prefix which is technically called "ahk_ critera" - I've been calling these "WinTitle types" and that is not the proper term....I just noticed the proper term today as I referred to the docs as I wrote this comment lol.

 

Please review this page, it goes into details about using various ahk_ criteria. If you were to use the exe name you need to use the proper ahk_ criteria that being the ahk_exe varient.  https://www.autohotkey.com/docs/v1/misc/WinTitle.htm

If you do this, your "SetTitleMatchMode, 2" line is not required because you're not really referring to a window title at any point in the script.

If you would rather refer to the window title then you need to adjust to the window's title in the WinWaitActive line. Titles do not require a specific ahk_ criteria to be defined since if no ahk_ criteria is defined it defaults to searching window's title. When using window's titles they are always case sensitive but as you likely learned can be matched differently using the different modes of SetTitleMatchMode. 2 is a partial match, and the game window is actually "Teenage Mutant Ninja Turtles: Shredder's Revenge" so it needs to be that or some sort of partial match if left in mode 2.

 

Troubleshooting tip. To see where your script is when running double click on the tray icon or you can select certain things by right clicking on it too.  (right click > Open will take you to the same page as double clicking tray icon) it shows all the history of the lines that have executed and the time taken to do so etc. If you checked this you would notice your script stops at the same spot each time. Use this to aid with troubleshooting problems or just seeing the flow of a script, etc.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

20 minutes ago, Cnells2000 said:

didnt know if i needed to add a comma to the sleep 1000 and sleep 2000 so i made a script with the commas and without.

it's wishy washy funny business with AHK. Per AHK's docs it is not clear even lmao. The syntax example shows it with a comma....but then scroll down to the examples and they did not use a comma 🤷‍♂️

So just a FYI, in reality it works both ways, with or without a comma, at least in AHK v1

  • Like 1
Link to comment
Share on other sites

37 minutes ago, skizzosjt said:

This line is messing things up for you

Holy s#!t. It was exactly what u said. everything works now. BTW, this is a perfect way to make games like SOR 4, TMNT shredders revenge, Etc work with keyboard controls for an arcade setting

Thank you very much @JoeViking245 and @skizzosjt! u guys are wonderful.

@JoeViking245 thank you for helping me simplify my script. I did'nt know u could add a 4 beside the direction prompt!

 

 

Skizzosjt Suggestion With JoeViking245 Script Result

 

  • Game On 1
Link to comment
Share on other sites

So Here is the Script at the end. Thank You guys.

Spoiler

SetKeyDelay, 100
SetTitleMatchMode, 2

Sleep, 3000

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


; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep, 3000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep, 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

 

  • Like 2
Link to comment
Share on other sites

@JoeViking245@skizzosjt wondering if u could help me with one more thing....I created the script for a practice fun for use on my pc and i just transitioned over to my actual arcade. Im now running the script  and it works the same bc i see it moving on a notepad. But i cant get it to focus on the program. even though the window is in focus. i changed the script at the beginning and extended the length it takes to begin and still nothing. the script runs and dissapears like its supposed to but it doesnt make the movements.  works on other windows like notepad, browser, File explorer, etc

My keyboard works fine and i can do the movements manually.....just cant get it to focus on the keyboard splitter program, even though its in focus. i disable startup also.

8 hours ago, skizzosjt said:

Troubleshooting tip. To see where your script is when running double click on the tray icon or you can select certain things by right clicking on it too.  (right click > Open will take you to the same page as double clicking tray icon) it shows all the history of the lines that have executed and the time taken to do so etc. If you checked this you would notice your script stops at the same spot each time. Use this to aid with troubleshooting problems or just seeing the flow of a script, etc.

i couldnt find this. the script is working the same though. its even doing the alt +F4 at the end on other windows. Just Not that window.

as u can see it focuses on other windows just not that one.

Edited by Cnells2000
Link to comment
Share on other sites

11 hours ago, Cnells2000 said:

i couldnt find this.

You had it highlighted right at the end of the video. ;) 

image.png.79a4c874ebeaceff10ef3329a366ea8a.png

 

To verify the script is doing something, add in some message boxes at key points.  Like right before the 1st "Send", add "MsgBox, About to send keys".  Then after those sends', "MsgBox, Keys sent Waiting for tmnt to exit".  And maybe some others if you feel like it.

 

The window is in-focus (you can see it), but does it have-focus (it's the active window)?  To be sure, after your 3 second pause, you could add in "WinActivate ahk_exe whateverGKS.exe".  (replacing the last part with your Gaming Keyboard Splitter executable)

  • Like 1
Link to comment
Share on other sites

@JoeViking245 I Still don't understand what this means.... Or how i would begin to type this

4 hours ago, JoeViking245 said:

Like right before the 1st "Send", add "MsgBox, About to send keys".  Then after those sends', "MsgBox, Keys sent Waiting for tmnt to exit".  And maybe some others if you feel like it.

 

 

Yes the window is in focus. Its the active window.

I added that winactivate thing u said. Hope i typed and placed it correctly.

Spoiler

SetKeyDelay, 100
SetTitleMatchMode, 2

Sleep, 3000

WinActivate ahk_exe Keyboard Splitter TMNT.exe

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


; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep, 3000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep, 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

 

 

Untitled.thumb.jpg.141a8d9cdfa28be44b5aba2f83d53e2a.jpg

The shortcut is named Keyboard Splitter TMNT

 

This Is What my Active And Non Active Window Looks Like

982255892_NotActive.thumb.png.8105a8c49bf36330bd55d9c4650e85a6.png

 

After Adding That Line, this is the video

 

I can press the keys manually. it just wont work automatically

Edited by Cnells2000
Link to comment
Share on other sites

51 minutes ago, Cnells2000 said:

I Still don't understand what this means.... Or how i would begin to type this

Use what Joe put in quotes. It will create a message box that will pop up and this is a good way to test scripts, debug and troubleshoot sorta thing. To be specific, this line would create what he suggested

MsgBox, Keys sent Waiting for tmnt to exit


 

51 minutes ago, Cnells2000 said:

I added that winactivate thing u said. Hope i typed and placed it correctly.

51 minutes ago, Cnells2000 said:

WinActivate ahk_exe Keyboard Splitter TMNT.exe

this line isn't working for you. The extension used for a shortcut is .lnk. Since it's not an executable the method you used here would be trying to activate a window that doesn't exist. You would need to define the actual program's executable file name not the shortcut you made. So whatever program that shortcut is linking to, you need to use that exe's name instead since you are using the ahk_exe criteria variant

 

Joe gave same advice - notice he said whatever the Gaming Keyboard Splitter executable is. You stuck in the shortcut link name with .exe tacked on the end instead

4 hours ago, JoeViking245 said:

you could add in "WinActivate ahk_exe whateverGKS.exe".  (replacing the last part with your Gaming Keyboard Splitter executable)

 

Edited by skizzosjt
adding msgbox example
  • Like 1
Link to comment
Share on other sites

Spoiler

Sleep, 6000

WinActivate ahk_exe KeyboardSplitter.exe

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


; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep, 3000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep, 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

@JoeViking245@skizzosjtafter adding that script

 

I added that msg box on another script, a little box comes in the middle of the screen saying all the msgs i typed. But it appeared behind launchbox even though i have startup disabled and alt and enters and directions went all over the place except for keyboard splitter.

 

Here Is Me running the script and waiting W/O Launchbox involved.

 

 

Still Not grabbing.

Edited by Cnells2000
Link to comment
Share on other sites

8 hours ago, Cnells2000 said:

Still Not grabbing.

To clarify, you got the script to work on one computer, but it doesn't work on a different computer?

In your 2nd video here, it looks like when you double-click the script, KeyboardSplitter takes focus.  But not 6 seconds later.  Which tells me, after you start the script, you click on KS to set focus.  So we don't know if the 2nd line of the script is even working.  Granted, KS has focus and after 6 seconds the key presses should be sent.

Speaking of lines in the script, try adding back-in the SetKeyDelay line.  Some apps can't handle a rapid succession of key inputs so they need that slight delay. If that line bothers you, you can go back to what the AI told you and put a Sleep after each keypress. These 2 do the exact same thing, it's just the 2nd way gives your brain more of a visual of what's going on (and is fugly ;)).

  • Like 2
Link to comment
Share on other sites

12 hours ago, JoeViking245 said:

To clarify, you got the script to work on one computer, but it doesn't work on a different computer?

correct. my actual arcade cabinet with usb keyboard and I-pac encoder

12 hours ago, JoeViking245 said:

In your 2nd video here, it looks like when you double-click the script, KeyboardSplitter takes focus.

In the 2nd video, i clicked on it manually with my mouse. i was just showing you it has the same results whether im in launchbox or not

 

Spoiler

SetKeyDelay, 100
SetTitleMatchMode, 2


Sleep, 3000

WinActivate ahk_exe KeyboardSplitter.exe

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


; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep, 3000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep, 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

The set Key delay was already at the top. I just forgot to copy that part by accident. the results are the recent videos above.

Link to comment
Share on other sites

11 hours ago, Cnells2000 said:

The set Key delay was already at the top. I just forgot to copy that part

Well that don't help me, help you. ;)  

 

11 hours ago, Cnells2000 said:

my actual arcade cabinet with usb keyboard and I-pac encoder

Presumably, if you press Alt and the arrow buttons etc. on the keyboard (on the Cab), Keyboard Splitter receives the inputs.  

Maybe on your cab (for some reason), you need to send it a more literal keypress.  Try using SetKeyDelay, 100, 50   This will hold the key down for 50 milliseconds and have the delay of 100 milliseconds between presses.  The only other thing might [remotely] cause an issue is, for your Alt command use "LAlt" instead of "Alt".  Beyond this, I'm at a loss as to why it's not receiving key inputs from AHK on your cab only.  

 

Out of curiosity, (assuming your I-Pac is in keyboard mode and not Xinput mode) instead of using the keyboard, are you able to press Player1-Button2 and then Player1 joystick in lieu of Alt, arrow keys?

 

  • Like 1
Link to comment
Share on other sites

On 7/1/2023 at 9:46 AM, JoeViking245 said:

Out of curiosity, (assuming your I-Pac is in keyboard mode and not Xinput mode

Definitely In keyboard Mode using 1256qwertyghjklzxcvbop, enter, and escape only.

Results Adding your line SetKeyDelay, 100, 50

Spoiler

SetKeyDelay, 100, 50
SetTitleMatchMode, 2


Sleep, 6000

WinActivate ahk_exe KeyboardSplitter.exe

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


; Wait until the process closes
Process, WaitClose, tmnt.exe

; give it a sec to completely close
Sleep, 3000

Send {Tab}

; Send Enter key
Send {Enter}
Sleep, 2000

; Send Alt + F4 to close the Keyboard Splitter Program
Send !{F4}

;not required
;ExitApp

 

Results are exactly as the same video above after applying this script

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...