Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

14 minutes ago, OldSkool8bit said:

I have tried reading through some of the .exe stuff but am just lost

I'll have to give you some homework then ;) Read about window stuff like  WinTitle and ahk_criteria, WinWait, WinClose, and WinWaitClose and you will find yourself using these a lot.

The loop you are using is an inefficient way to do what you want. Using the stuff I mention above is more practical.

And Joe employed yet another method that is just as effective by using a While loop that checks every 700ms if the process mk11.exe exists.

So add While loops to that reading list too lol!  While loop is the more efficient way to doing a check within a loop like what you started with.

 

20 minutes ago, OldSkool8bit said:

In AHK V2 if that matters

Yes it does matter! Don't use V2 unless you actually want to deep dive learn AHK. 99% of the help out there is going to be in V1 as V2 only recently became official so in next several years it would be possible that the tides have turned and there is equal if not more help shared that is meant to be used with V2. But right now V1 is still sorta "king" if you will, at least in this world of frontends and emulation support. Every script and advice shared on this forum is going to be V1 syntax FYI. You may honestly be the first person to post anything in V2 syntax, there's a first for everything!

 

31 minutes ago, JoeViking245 said:

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.

It is V2 but the parenthesis they're using are unnecessary. V2 send command, the only difference to V1 is V2 requires double quotes around the line. V2 has everything expression based now.

 

@OldSkool8bit, I would combine the lines, for ex, this sort of format looks much easier to read.  Ran OK with a test on my end!

Send "{Alt}{Right 4}{Down}"
Sleep 1000
Send "{Right}"
Sleep 1000
Send "{Down}{Enter}"
Sleep 2000
Send "{Tab}{Enter}"
  • Like 1
Link to comment
Share on other sites

@skizzosjt @JoeViking245 I FINALLY GOT IT. I appreciate the help. Even if you couldnt help much with V2 the help you gave from a V1 standpoint helped me think of commands in a different light. I will leave the entire script here  in case someone else has an issue/need for this.

Again what this script will do...Load a game and your preconfigured keyboard keys mapped to xbox controls (which you have to do manually and reach out if you need help) in Keyboard Splitter, and then allow the AHK V2 script to continually run allowing you to play the game as much as you want with your arcade stick and buttons acting as virtual controllers. When you stop the game Keyboard Splitter as well as the script will automatically stop. I wanted to use Keyboard Splitter because it is DirectInput which allows my LED Blinky program to still light up buttons in LaunchBox/BigBox when playing through the FE as LED Blinky doesnt work with XInput.

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}")

Sleep 35000


if ProcessExist("mk11.exe")

 loop
    {
        if ProcessExist("mk11.exe")
    
            Continue 
        
        Sleep 3000
        
        Send("{Tab}")
        
        Send("{Enter}")
        
        Send("{Tab}")
        
        Send("{Enter}")
        
        Send("{Enter}")
            
        ExitApp()    
    
    }

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
1 hour ago, Jayinem said:

I have launchbox at startup on Windows 10 but how do you start it minimized? I have tried WinMinimize, WinHide and adding Min and Hide after run launchbox.exe nothing works. 

How exactly are you starting LB at startup (show your work)?  Regardless, the problem with WinMinimize (etc.) is the LaunchBox loading window is titled "LaunchBox" and the ahk_exe is "LaunchBox.exe".  The main LB window that eventually appears is the exact same.  And, they both have the same pid.

When using the Min option, you'll actually want to Run "D:\LaunchBox\Core\LaunchBox.exe" (not the exe in the root folder).  Not sure if that'll work ("Min") for what you're wanting. But you do want to Run the 'other' exe from a script (or batch file) for best success.

If you know how long it takes for the LaunchBox main window to load, in your AHK script, you could add a sleep timer right before WinMinimize.

 

Plan "B" is to wait, then click the underscore (minus) symbol in the upper-right corner when the main window appears. ;) 

image.png.82266c475b431d1ff1c9c190416b72fd.png

Link to comment
Share on other sites

  • 2 weeks later...

I just put on the arcade patch and the dgvoodoocpl patch to get house of the dead 3 in arcade mode and also in full screen 16-9 .

Everything is fine but I have the problem that the pause button of launchbox and bigbox doesn't work at all, it seems that the game completely absorbs the screen property. Ahk scripts don't work either, I tried this :

Joy9::
if GetKeyState("Joy6")
    Sendinput Esc
Return

Joy6::
if GetKeyState("Joy9")
    Sendinput Esc
Return

But it does not work.
It only seems to take into account if I press esc on the keyboard, what can I do?

Link to comment
Share on other sites

13 minutes ago, JoeViking245 said:

I don't think it makes a difference, but try putting a "1" in front of the "joy" (1joy9).   

SendInput can be tricky.  Try Send, {Esc} instead.

 

Whether SendInput or Send you made sure to put the key that is being sent in braces. If sbaby forgot them that would explain why it doesn't work.

 

44 minutes ago, Sbaby said:

I just put on the arcade patch and the dgvoodoocpl patch to get house of the dead 3 in arcade mode and also in full screen 16-9 .

I followed this link: 
https://youtu.be/f_yEgRcbMw8

Everything is fine but I have the problem that the pause button of launchbox and bigbox doesn't work at all, it seems that the game completely absorbs the screen property. Ahk scripts don't work either, I tried this :

Joy9::
if GetKeyState("Joy6")
    Sendinput Esc
Return

Joy6::
if GetKeyState("Joy9")
    Sendinput Esc
Return

But it does not work.
It only seems to take into account if I press esc on the keyboard, what can I do?

Does the script you're using actually have Esc as literally just "Esc" ? Not sure if that is the exact script or if you just missed them when typing it out

Keys needs to be in braces {}. Having a line like this....

    Sendinput Esc

Will type out "Esc". It is sent as literal text

If so, it's sending the equivalent of hitting E (shift plus E because it is capitalized), s, c. Rather than sending the actual escape key. It might be as simple as adding braces around {Esc}

Link to comment
Share on other sites

7 hours ago, JoeViking245 said:

I don't think it makes a difference, but try putting a "1" in front of the "joy" (1joy9).   

SendInput can be tricky.  Try Send, {Esc} instead.

 

 

6 hours ago, skizzosjt said:

Whether SendInput or Send you made sure to put the key that is being sent in braces. If sbaby forgot them that would explain why it doesn't work.

 

Does the script you're using actually have Esc as literally just "Esc" ? Not sure if that is the exact script or if you just missed them when typing it out

Keys needs to be in braces {}. Having a line like this....

    Sendinput Esc

Will type out "Esc". It is sent as literal text

If so, it's sending the equivalent of hitting E (shift plus E because it is capitalized), s, c. Rather than sending the actual escape key. It might be as simple as adding braces around {Esc}

 

 

I tried this :

Joy9::
if GetKeyState("1Joy6")
     Send, {Esc}
Return

Joy6::
if GetKeyState("1Joy9")
    Send, {Esc} 
Return

and also this :

;for exit with one press of XBOX Guide Button
$vk07:: 
Process, Close, hod3pc.exe

not work 😔

Link to comment
Share on other sites

 @Sbaby

In your latest script, you only added some of the 1's.  Initially I was thinking to add them to all joy's.  I looked at some notes I had on this and see I have them placed only on the 1st joy in the method.  Opposite of what you did.  Give this a try.  (Here, press joy6 THEN joy9 [in that order])

1Joy9::
if GetKeyState("Joy6")
  Send, {Esc}
Return

If this method isn't intermixed with a bunch of others, and its intent is to exit the game, change "Return" to "ExitApp".  Otherwise the script will continue to run in the background (depending on where you actually placed it. See below.).

 

There's a chance that this PC game might not work with AHK scripts.  To find out, you can try something simple using the keyboard to 'prove it can detect AHK'.

j::
  WinClose, ahk_exe hod3dpc.exe
  ExitApp

When in game, press j and see if it closes the game.  If this doesn't work, chances are you won't be able to use AHK scripts with that particular patched game.


Also, you mentioned something about 'Pause'.  Are you putting the script in one of the pause sections?  Or is this different from your pause issue and it's going in the Running Script section?  Can you share screenshots of where this is being placed?

Does this game have a 'Menu' that you can select "Exit" from?  (Most, if not all PC games do.)  If so, it's recommended to exit via the menu for all PC games.

Link to comment
Share on other sites

@Sbaby and @JoeViking245

It is recommended to launch this game mod as admin - if Sbaby is doing that then the ahk won't work unless also launched as admin.

I have the game exiting via arcade box and keyboard - try adding the below parts to JoeViking245 script and see if that work

As per JoeViking245 if you share screenshots it will make it easier to help, I run my exit ahk as a separate additional app as it does other things as well before and after the game but you could do the same with the running ahk tab

Cheers

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
SetTitleMatchMode, 2
DetectHiddenWindows, on
#SingleInstance, Force

 

Edited by Kiinkyfoxx
Link to comment
Share on other sites

@JoeViking245 and @Kiinkyfoxx

 

I didn't enter any scripts in the pause sections of launchbox?

The game's pause menu was disabled by the patch to turn it from a pc game to an arcade game

The results are the same whether I use Launchbox or just start the game from the script without Launchbox

With administrator privileges, "Process, Close" and "Submit, {Esc}" work, while "WinClose" does not.
This is my game startup script, tell me if you like it

------------------------------------------------------------------------------------------------------------------------------------------------

 

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
SetTitleMatchMode, 2
DetectHiddenWindows, on
#SingleInstance, Force

sleep 2000
Run "M:\Giochi\Emulatori\MS-Windows Arcade PC\Roms\THE HOUSE OF THE DEAD 3_EU Arcade\Hotd3Arcade_Launcher.exe"

;for exit with one press of XBOX Guide Button
$vk07:: 
Process, Close, hod3pc.exe

;for exit with combination press of two buttons
Joy5::
if GetKeyState("Joy7")
  Send, {Esc}
exitapp
Return

 

------------------------------------------------------------------------------------------------------------------------------------------------

Now I can use the joystick to exit the game by choosing between the home button or with the combination of two keys, but I can't enter the pause menu of BigBox and Launchbox. Is there any way to do this?

Edited by Sbaby
  • Game On 1
Link to comment
Share on other sites

Hi guys, could someone please help me with a script that automatically presses Control + Alt + F5 once Mame has launched?

I tried: 

Sleep, 3000
Send {LCtrl Down}{LAlt Down}{F5 Down} {LCtrl Up}{LAlt Up}{F5 Up}

And many other variants, and can't get it to work.

(I need it to disable shaders on a specific platform, I know I can just use another Mame with another .ini but would like to take advantage of the running script feature in Launchbox.)

 

Link to comment
Share on other sites

3 hours ago, kanjifreak said:

Hi guys, could someone please help me with a script that automatically presses Control + Alt + F5 once Mame has launched?

MAME needs a key delay to catch AHK key presses.  Try this:

SetTitleMatchMode, 2
SetKeyDelay, 125, 50

Loop
{
   ifwinactive, MAME  ;title is case sENsaTivE
   {
      ;sleep 3000
      send ^!{F5}
      break
   }
}

Note that "sleep" is commented out.  If it's sending Ctrl+Alt+F5 too soon, remove the semicolon at the beginning of that line.

  • Thanks 1
Link to comment
Share on other sites

5 hours ago, JoeViking245 said:

MAME needs a key delay to catch AHK key presses.  Try this:

SetTitleMatchMode, 2
SetKeyDelay, 125, 50

Loop
{
   ifwinactive, MAME  ;title is case sENsaTivE
   {
      ;sleep 3000
      send ^!{F5}
      break
   }
}

Note that "sleep" is commented out.  If it's sending Ctrl+Alt+F5 too soon, remove the semicolon at the beginning of that line.

Thank you so much, the script works perfectly now!!

Edited by kanjifreak
  • Game On 1
Link to comment
Share on other sites

Hey everyone,

I have another problem I'd lie to solve with an AHK script and as always, I'm a t a loss, haha. It is similar to my last problem when I wanted to run and close a program called XOutput.exe with my retroarch emulator.

This is the script that was suggested to me and it worked:
 

run, M:\LaunchBox\Emulators\RetroArch - Original Controllers (PSX)\XOutput\XOutput.exe, M:\LaunchBox\Emulators\RetroArch - Original Controllers (PSX)\XOutput, min

Esc::
{
   WinClose, ahk_exe XOutput.exe
}

!F4::
{
   WinClose, ahk_exe XOutput.exe
}
Send, !{F4}


Now I want to rund and close a program called "BetterJoy" whenever I start a Switch game with yuzu emulator. I can get BetterJoy to launch together with yuzu, but the shutdown process doesn't work. My guess is that while XOutput turns up as a program in task manager, Betterjoy is listed under "Background Processes". So I need to find a way to automatically kill that background process, once I shot down yuzu.

Here is what I got so far (again, launching works, but shut down won't):
 

run, M:\LaunchBox\Emulators\Yuzu\BetterJoy\BetterJoyForCemu.exe, M:\LaunchBox\Emulators\Yuzu\BetterJoy, min

Esc::
{
   WinClose, ahk_exe BetterJoyForCemu.exe
}

!F4::
{
   WinClose, ahk_exe BetterJoyForCemu.exe
}
Send, !{F4}

 

Edited by SiriusVI
Link to comment
Share on other sites

Yeah, I figured it out myself! That's first, haha.

So this script opens yuzu with betterjoy and then closes both of them when hitting escape:
 

run, M:\LaunchBox\Emulators\Yuzu\BetterJoy\BetterJoyForCemu.exe, M:\LaunchBox\Emulators\Yuzu\BetterJoy, min

Esc::
{
   WinClose, ahk_exe yuzu.exe
   Process, Close, BetterJoyForCemu.exe
}

!F4::
{
   WinClose, ahk_exe yuzu.exe
   Process, Close, BetterJoyForCemu.exe
}
Send, !{F4}

 

Link to comment
Share on other sites

Hi friends, 

for Duckstation standalone, there's something wrong with the pause configuration, the first time it doesn't work, what should I do? so far I've done this but it doesn't work

; Duckstation pause space key by default
Send {Space down}
Sleep 50
Send {Space up}

Link to comment
Share on other sites

13 hours ago, Sbaby said:

Hi friends, 

for Duckstation standalone, there's something wrong with the pause configuration, the first time it doesn't work, what should I do? so far I've done this but it doesn't work

; Duckstation pause space key by default
Send {Space down}
Sleep 50
Send {Space up}

Since space is the default key for pausing the game, you shouldn't need anything in the Pause Script section for the emulator. Just tested it with and without your pause script, and pressing Space paused the game in both cases.  

Link to comment
Share on other sites

2 hours ago, JoeViking245 said:

Since space is the default key for pausing the game, you shouldn't need anything in the Pause Script section for the emulator. Just tested it with and without your pause script, and pressing Space paused the game in both cases.  

The pause menu and its controls work fine, saving, exiting, etc. work fine, the problem is that while in the pause menu the game continues to play and does not stop.

The game with the space key via the keyboard goes to pause, but via the bigbox pause menu it works badly, randomly it works

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