Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

10 hours ago, Cnells2000 said:

Hey Everyone Im Trying to figure how to make a script where once i click the .bat, it waits 2 minutes before beginning then i need it to push the down key every 17 seconds or so repeating for at least 4 hours. i know. its crazy but i need it. can someone help me please?

Not sure the key press is possible in a batch file, but since you're asking in the AutoHotkey thread, how about an AHK script instead?

SetTimer, Quit, % 14520000 ; (4hr * 60min * 60sec * 1000) + 2min = 14,520,000 = 4 hours + the 2 minute wait
Sleep, 120000 ; 2min * 60sec * 1000

Loop
{
  Send, {Down}
  Sleep, 17000  ; 17sec * 1000
}

Quit:
ExitApp

Though I suppose you could create a batch file that launches the AHK script. 

  • Thanks 1
Link to comment
Share on other sites

15 hours ago, JoeViking245 said:

Not sure the key press is possible in a batch file, but since you're asking in the AutoHotkey thread, how about an AHK script instead?


SetTimer, Quit, % 14520000 ; (4hr * 60min * 60sec * 1000) + 2min = 14,520,000 = 4 hours + the 2 minute wait
Sleep, 120000 ; 2min * 60sec * 1000

Loop
{
  Send, {Down}
  Sleep, 17000  ; 17sec * 1000
}

Quit:
ExitApp

Though I suppose you could create a batch file that launches the AHK script. 

Thank you Joe. that did exactly what i needed much thanks

  • Like 1
Link to comment
Share on other sites

Hi, sorry for my bad English, I don't speak the language so I have to use the translator.

I had made a post I asked if there was any ahk, to change the screen resolution, why I use a CRT TV, and I work with two resolutions, 2560x240p and 640x480i, I wanted to make a switch between them before running the emulator.

After working hard and with the help of my Sensei, I managed to solve this, using this program:

https://tools.taubenkorb.at/change-screen-resolution/

Using its command line parameters, it was possible to switch to a custom resolution that I created on my nvidia video card, in the case of the script below, 640x480i that I had created with the CRU program.

https://www.monitortests.com/forum/Thread-Custom-Resolution-Utility-CRU

Segue o script que eu estou usando, para primeiro mudar a resolução da tela de 240p para 480i, depois arrastar a tela até a tv crt, e depois deixar ela em tela cheia.
E depois que o emulador para fechado, retornar a resolução de 240p:

#NoEnv
Run, G:\Emuladores\Playstation 2 Upscale 16x9\ChangeScreenResolution.exe /w=640 /h=480 /b=32 /f=60 /d=1
 Sleep, 3650    ;wait 3 seconds
 Send #+{Left}  ;Send Win+Shift+right
 Sleep, 900    ;wait 0.9 seconds
 Send !{Enter}  ;Send {Alt Down}{Enter}{Alt Up}
 Return
; This section closes PCSX2 when pressing Escape
$Esc::
{
    Process, Close, {{{StartupEXE}}}
Run, G:\Emuladores\Playstation 2 Upscale 16x9\ChangeScreenResolution.exe /w=2560 /h=240 /b=32 /f=60 /d=1
}
 

 

 

 

  • Like 1
Link to comment
Share on other sites

Anyone have an AHK script example to switch Gun4IR modes from full screen to 4:3 that will run on start shutdown of MAME? 

Here's the commands to enable/disable

Enables 4/3
{
     SerialSend.exe /baudrate 9600 /devnum 5 "M3x1"
}

$

Enables 16/9
{
SerialSend.exe /baudrate 9600 /devnum 5 "E"
}

Edited by Krakatoa
Link to comment
Share on other sites

If those are the commands you want to send when MAME starts (4:3) and when MAME exits (16:9), In the Running AutoHotkey tab of your MAME emulator, put:

Run, SerialSend.exe /baudrate 9600 /devnum 5 \"M3x1\"

$esc::
{
   Run, SerialSend.exe /baudrate 9600 /devnum 5 \"E\"
   WinClose, ahk_exe mame.exe
}

The \ (slash) in front of the quotes are needed to make them literal.

If SerialSend.exe is not in your PATH and you need to point directly to the file location, put that full path in quotes. i.e.

Run, "F:\My\Extra Programs\SerialSend.exe" /baudrate 9600 /devnum 5 \"M3x1\"

Do that on both "Run" lines.

Lastly, if your using an older release of MAME, change mame.exe to mame64.exe.  (or to whatever variant of the MAME executable you're using).

Link to comment
Share on other sites

10 hours ago, JoeViking245 said:

If those are the commands you want to send when MAME starts (4:3) and when MAME exits (16:9), In the Running AutoHotkey tab of your MAME emulator, put:


Run, SerialSend.exe /baudrate 9600 /devnum 5 \"M3x1\"

$esc::
{
   Run, SerialSend.exe /baudrate 9600 /devnum 5 \"E\"
   WinClose, ahk_exe mame.exe
}

The \ (slash) in front of the quotes are needed to make them literal.

If SerialSend.exe is not in your PATH and you need to point directly to the file location, put that full path in quotes. i.e.


Run, "F:\My\Extra Programs\SerialSend.exe" /baudrate 9600 /devnum 5 \"M3x1\"

Do that on both "Run" lines.

Lastly, if your using an older release of MAME, change mame.exe to mame64.exe.  (or to whatever variant of the MAME executable you're using).

thank you!!

  • Game On 1
Link to comment
Share on other sites

this one is driving me nuts!  singe 2.o, laser disc games, i'll use dragons lair 2 as my example.

i only want to use JoyToKey when starting the app and to quit it when the app is closed.

if i MANUALLY start joyToKey and then launch the DL2.BAT, everything works.

when i add the joytokey.exe to dragon lairs "additional apps" and then start the game, the j2k app loads (it is in the task bar) but the joystick does nothing.  this is really odd, the app works fine when starting manually.

i have also tried the below code in a AHK script as my additional app.  it starts but the game is minimized to the task bar, i have to manually blow it up.  and then when hitting ESC to exit, i go back to desktop but the game is minimized to task bar.  fyi, for the jopytopkey.bat in the AHK script below, i only have one line:  taskkill /F /im JoyToKey.exe

and again, outside of LB, if i run the close bat, it dopes what it is supposed to.  please help, i'm going nuts!

 

Run, S:\Tools\Joy2Key\JoyToKey\JoyToKey.exe

$Esc::
{
Run, S:\Tools\Joy2Key\JoyToKey\JoyToKeyClose.bat
WinClose, ahk_exe {{{StartupEXE}}}
}

Link to comment
Share on other sites

First I am not familiar with the Singe emulator. (And I only have a basic understanding of batch scripting.) But what does your DL2.bat look like? If you use for example:

 

Start "" "S:\Tools\JoyToKey\JoyToKey.exe"

Start "" "S:\emulators\Singe.exe" -bla -bla -parameters

 

A bat file like that runs for less than a second and then closes. And as far as LaunchBox is concerned the emulator\startupEXE has closed and anything entered in the "Running AutoHotKey Script" tab wont work anymore. The trick is to keep the script or bat file "open" for as long as you are playing. In a bat file you can use:   start /wait "" (start application and then wait for it to exit). So you can use for example:

 

Start "" "S:\Tools\JoyToKey\JoyToKey.exe" "Dragons Lair 2"

Start /wait "" "S:\emulators\Singe.exe" -bla -bla -parameters

Start "" "S:\Tools\JoyToKey\JoyToKeyClose.bat"

 

- That bat file starts JoyToKey with the Dragons Lair 2 JoyToKey profile (use the name of your Dragon Lair 2 profile exactly as you have it in JoyToKey)

- Starts Singe

- Waits for Singe to close

- Starts your JoyToKeyClose.bat

 

In regard to your AHK exit script. WinClose, ahk_exe {{{startupEXE}}} sees your DL2.bat as the startupEXE. It will close the DL2.bat (but the bat has already terminated) and not the emulator. Use this instead:

$Esc::

{

WinClose, ahk_exe Singe.exe

}

 

*Edit*

I want to make clear that you can do the things you want to do with the bat file or with the autohotkey script. You also can do it like this:

Bat file:

Start /wait "" "S:\emulators\Singe.exe" -bla -bla -parameters

AHK:

Run, S:\Tools\JoyToKey\JoyToKey.exe "Dragons Lair 2"

 

$Esc::

{

Process, Close, JoyToKey.exe

WinClose, ahk_exe Singe.exe

}

P.s. I didn't use your exact paths in my examples. Substitute for your own paths.

P.p.s. In JoyToKey you can auto associate profiles with applications or start JoyToKey with a profile. Choose one or the other. Using both can lead to complications.

Edited by Koroth
Link to comment
Share on other sites

thanks for the reply, here is what i'm finding, here is my bat after your edit suggestions.  fyi, i replaced the close BAT with the one line that was in the bat.  fyi #2, i only have one profile in j2k so the few emu's that use it, all use that one profile loaded when j2k starts

Start "" S:\Tools\Joy2Key\JoyToKey\JoyToKey.exe
Start /wait "" Singe.exe -k -z -e 60 -d DL2e\Index -v DL2e\Movie\DL2e.mp4 -w DL2e\DL2e.singe
Start "" taskkill /F /im JoyToKey.exe

game starts minimized to the task bar, i can hear it running.  if i click the taskbar singe icon, i go full screen and i can play.  other than this, its running and doing whats expected.

i didnt try the AHK cause the BAT is SO close!  any thoughts on that?

 

Link to comment
Share on other sites

1 hour ago, d8thstar said:

game starts minimized to the task bar, i can hear it running.  if i click the taskbar singe icon, i go full screen and i can play.  other than this, its running and doing whats expected.

I have never used Singe so I cant diagnose Singe problems. But to diagnose if the minimizing is a LaunchBox problem , can you disable the startup screen for your game (if you have it enabled). Right click your game > Edit > Startup/Pause > Tick "Override default Startup Screen Setting" and click "Customize".

1883543020_Schermopname(30).thumb.jpg.1b3273d0d493a029cbc4fac4357f69c4.jpg

If  "Enable Game Startup Screen" is ticked, untick. Also you could try lowering the "Startup Load delay".

174623691_Schermopname(31).thumb.jpg.d8e711179b58bbdc7757c05c01f636cf.jpg

*Edit*

It is also possible that the start of JoyToKey is interfering with the start of Singe. If JoyToKey starts in a window, you can start it minimized via the bat file. Add a /min to the first line:

Start /min "" S:\Tools\JoyToKey\JoyToKey\JoyToKey.exe

You can also set a delay between starting JoyToKey and Singe. Between the first and second line add:

timeout /t 5 /nobreak

(5 = 5 seconds, you can change it to something lower if you want.

Edited by Koroth
Link to comment
Share on other sites

  • 3 weeks later...

I am using Launchbox/Big Box in an arcade cabinet. I use an IPAC2 and have it set in keyboard mode for all of the emulators I am running and the Big Box interface. The problem is some Steam games (added as Windows games) like MK11 that do not work with 2 players with the IPAC in keyboard mode. Using the WinIPAC utility and CMD with authotkey I wrote the following to be executed when launching one of these games. It will load a gamepad configuration file that is stored in the WinIPAC directory and wait for me to press my hotkey to exit the game, once pressed it will exit the game and switch back to keyboard. 

Quote

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
run, %comspec% /c cd C:\Program Files (x86)\WinIPAC V2 && Winipac.exe ipac_gamepad.ipc
$Joy9::
{
Send !{f4}
run, %comspec% /c cd C:\Program Files (x86)\WinIPAC V2 && Winipac.exe ipac_keyboard.ipc
ExitApp
}
ExitApp

 

Link to comment
Share on other sites

  • 3 weeks later...

Hey does anyone know to trigger exiting emulators if a button is held down for 2 seconds?

This is my script, at the moment 1 press opens BigBox closes emulators etc, I would like it so that the button must be held for 2 seconds and for it to not repeat while being held.

vk07::

if !WinExist("ahk_exe yBigBox.exe")
    Run C:\Users\Jack\LaunchBox\Core\BigBox.exe   
else
    WinActivate, ahk_exe BigBox.exe

Run %A_ScriptDir%\nircmd.exe setdefaultsounddevice "32W_LCD_TV" ;

send {esc}

WinClose, ahk_exe retroarch.exe

WinClose, ahk_exe Dolphin.exe

WinClose, ahk_exe pcsx2.exe

WinClose, ahk_exe pcsx2.exe

WinClose, ahk_exe PPSSPP

WinClose, ahk_exe kodi.exe

WinClose, ahk_exe citra-qt.exe

WinClose, ahk_exe Cemu.exe

Send {y}

Link to comment
Share on other sites

 

vk07::
{
  KeyWait, vk07, T2       ;wait to see if the Guide buttom is held for 2 ("T2") seconds
  If (ErrorLevel)         ;if held for 2 seconds, then...
  {
     if !WinExist("ahk_exe BigBox.exe")
       Run C:\Users\Jack\LaunchBox\Core\BigBox.exe   
     else
       WinActivate, ahk_exe BigBox.exe

     Run %A_ScriptDir%\nircmd.exe setdefaultsounddevice "32W_LCD_TV" ;
     send {esc}
     WinClose, ahk_exe retroarch.exe
     .....
     .....
     Sleep 1000         ;should eliminate 'repeat presses'
  }
  else                  ;if held for less that 2 seconds
  {
     vk07::vk07         ;then the Guide button is just the Guide button
  }
}

 

Link to comment
Share on other sites

Hey Joe, thanks for this, I tried it and it doesn't load BigBox for some reason. Any ideas? This is what I have put in the script:

vk07::
{
  KeyWait, vk07, T2       ;wait to see if the Guide buttom is held for 2 ("T2") seconds
  If (ErrorLevel)         ;if held for 2 seconds, then...
  {
     if !WinExist("ahk_exe BigBox.exe")
       Run C:\Users\Jack\LaunchBox\Core\BigBox.exe   
     else
       WinActivate, ahk_exe BigBox.exe

     Run %A_ScriptDir%\nircmd.exe setdefaultsounddevice "32W_LCD_TV" ;
     send {esc}
     WinClose, ahk_exe retroarch.exe
     WinClose, ahk_exe Dolphin.exe
     WinClose, ahk_exe pcsx2.exe
     WinClose, ahk_exe pcsx2.exe
     WinClose, ahk_exe PPSSPP
     WinClose, ahk_exe kodi.exe
     WinClose, ahk_exe citra-qt.exe
     WinClose, ahk_exe Cemu.exe
     Send {y}
     Sleep 1000         ;should eliminate 'repeat presses'
  }
  else                  ;if held for less that 2 seconds
  {
     vk07::vk07         ;then the Guide button is just the Guide button
  }
}

 

Link to comment
Share on other sites

You may have to 'pay' to get it to work.  Try putting a "$" in front of vk07 (just the 1st one)

$vk07::
{
  KeyWait, vk07, T2       ;wait to see if the Guide buttom is held for 2 ("T2") seconds
  If (ErrorLevel)         ;if held for 2 seconds, then...
  {
   ...........

I've only ever tested this ("long-press") with 'regular' buttons (i.e. 1Joy1).  Hopefully the money helps. ;) 

Link to comment
Share on other sites

1 hour ago, jacks897 said:

still not working

So I actually connected my controller and did some testing with the Guide button and yup! couldn't get it work "directly" with a long-press.

"Indirectly" (maybe not the correct use of the word) I was able to get it to 'work' using a long-press button combo.  

This example you press and hold the Guide button (vk07) and then tap the "B" (1Joy2) button, while still holding the Guide button for 2 [more] seconds.

1Joy2::
{
  KeyWait, vk07, T2
  If (ErrorLevel)
  {
   ...........

If you swap the 2 buttons in the script, it doesn't work.  In that case, it seems like the Guide button is acting like a momentary switch [which you can't hold down].

Of course, you can use any button combo for the long-press effect, or any single button for a long-press as long as it's not the Guide button. :D

 

If you decide to use this 'example' remember to set the "B" button at the bottom of the script to be "B" [if not long-pressed].

...........
else                  ;if held for less that 2 seconds
  {
     Joy2::Joy2       ;then the "B" is just "B"
  }
}

 

  • Thanks 1
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...