Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

12 hours ago, Cnells2000 said:

Hello guys!! i have a pesky PC game with no exit option. the only way i can close it is Alt + F4. can someone help me with a script that i can place in an .AHK file to escape this PC game by pressing ESC and that sends the Alt + F4?

 

also would i ✔️ the run before main application box? thank you in advance..

The contents of your script would be

Esc::
Send, !{F4}

Set it up as an Additional App the exact same way you did here:  

 

 

Not having a built-in "Exit to Windows" option is odd.  But the script should work for you.  It may not work if the game's executable spawns another file to start the actual game.  There's one sure way to find out if it'll work. ;) 

  • Thanks 1
Link to comment
Share on other sites

14 hours ago, JoeViking245 said:

The contents of your script would be

Esc::
Send, !{F4}

Set it up as an Additional App the exact same way you did here:  

 

 

Not having a built-in "Exit to Windows" option is odd.  But the script should work for you.  It may not work if the game's executable spawns another file to start the actual game.  There's one sure way to find out if it'll work. ;) 

thanks man

Link to comment
Share on other sites

Hi everyone, 

if someone could point me to the right direction, currenlty I have retroarch to quit  a game with (with hotkey enabled)  "enter+esc" I also have the confirm quit, so I have to press the esc twice.

I have demul working and before adding the hotkey enabled, my muscle memory presses the esc button twice, which if you pressed fast enough, closes also the last window opened, which would be launcbox (i've tested it with file explorer too) so i'm guessing its using "alt+f4) as default. 

I'd like to get a script to be able to use 2 buttons to close demul, perferable "enter+esc" and if possible to also confirm quit (not necessary, but if its possible please) my reason is I have kids running around and like to press all sorts of buttons, and if I could eliminate them pressing just esc while i'm in game thatd be great. 

 

Thanks. 

Link to comment
Share on other sites

1 hour ago, huffyX0 said:

I have demul working

Not a direct answer to your question, but considering you are already using RetroArch, you're better off using the Flycast core for Dreamcast, Atomiswave, Naomi and Naomi 2. Demul is pretty much dead.

And as far as exit scripts go, I would avoid using Alt + F4 exactly for the reason you're describing. In an exit script it's much better to specify exactly which window should be closed. Like:

WinClose, ahk_exe demul.exe

or

WinClose, ahk_exe {{{StartupEXE}}}

*Edit*

To give an example of an exit script for Demul, I have the following exit script that exits Demul with Escape in LaunchBox > Tools > Manage > Emulators > Demul, in the "Running Script" tab:

$Esc::
{
WinClose, ahk_exe {{{StartupEXE}}}
}

This only closes Demul and nothing else.

Edited by Your Friendly A.I Overlord
Link to comment
Share on other sites

17 minutes ago, Your Friendly A.I Overlord said:

Not a direct answer to your question, but considering you are already using RetroArch, you're better off using the Flycast core for Dreamcast, Atomiswave, Naomi and Naomi 2. Demul is pretty much dead.

And as far as exit scripts go, I would avoid using Alt + F4 exactly for the reason you're describing. In an exit script it's much better to specify exactly which window should be closed. Like:

WinClose, ahk_exe demul.exe

or

WinClose, ahk_exe {{{StartupEXE}}}

*Edit*

To give an example of an exit script for Demul, I have the following exit script that exits Demul with Escape in LaunchBox > Tools > Manage > Emulators > Demul, in the "Running Script" tab:

$Esc::
{
WinClose, ahk_exe {{{StartupEXE}}}
}

This only closes Demul and nothing else.

Thanks, so theres no way to edit this script to press 2 buttons to exit demul? 

 

I'm only using demul for marvel vs capcom 2, because i have a really weird issue. here is my issue: https://forums.launchbox-app.com/topic/68048-very-weird-mvsc2-kunundrum/

 

but yea thanks for the instructions, I was actually putting it under exit script. 

Link to comment
Share on other sites

1 hour ago, huffyX0 said:

so theres no way to edit this script to press 2 buttons to exit demul? 

 

Of course there's a way. ;) It's a different approach for pressing [controller] buttons.  But for pressing keyboard keys, it goes something like this:

Enter & Esc::
   WinClose, ahk_exe {{{StartupEXE}}}
Enter::Enter

If you holder Enter then hit Escape, it will execute the WinClose statement.  Otherwise, if your press Enter and let go, it will 'press Enter'.

  • Like 1
Link to comment
Share on other sites

2 hours ago, JoeViking245 said:

 

Of course there's a way. ;) It's a different approach for pressing [controller] buttons.  But for pressing keyboard keys, it goes something like this:

Enter & Esc::
   WinClose, ahk_exe {{{StartupEXE}}}
Enter::Enter

If you holder Enter then hit Escape, it will execute the WinClose statement.  Otherwise, if your press Enter and let go, it will 'press Enter'.

WOW, this actually works! Thanks a bunch. 

  • Game On 1
Link to comment
Share on other sites

11 hours ago, Your Friendly A.I Overlord said:

Not a direct answer to your question, but considering you are already using RetroArch, you're better off using the Flycast core for Dreamcast, Atomiswave, Naomi and Naomi 2. Demul is pretty much dead.

And as far as exit scripts go, I would avoid using Alt + F4 exactly for the reason you're describing. In an exit script it's much better to specify exactly which window should be closed. Like:

WinClose, ahk_exe demul.exe

or

WinClose, ahk_exe {{{StartupEXE}}}

*Edit*

To give an example of an exit script for Demul, I have the following exit script that exits Demul with Escape in LaunchBox > Tools > Manage > Emulators > Demul, in the "Running Script" tab:

$Esc::
{
WinClose, ahk_exe {{{StartupEXE}}}
}

This only closes Demul and nothing else.

I figured out what the problem was in my other thread. now i don't need to use demul lol. 

Link to comment
Share on other sites

  • 2 weeks later...

Found some neat script recently to force any window into basically a borderless fullscreen mode. Here is the link to the site with the detailed instructions

 

http://tech.yeesiang.com/autohotkey-force-app-fullscreen-automatically/

 

I followed the instructions and it worked well. I then adapted this to work without the need for creating a bat file and executable, doing it exclusively in AHK. for example...

 

w = 3840
h = 2160

WinWaitActive, ahk_exe Dolphin.exe
WinGet Style, Style, A
WinGetPos, X, Y, Width, Height, A
WinSet, Style, -0xC40000, A
WinMove,A,,0,0,w,h

ExitApp

 

I tested this on Dolphin, and that was a little bit of a mistake that annoyed me for a hot min. Since that emulator has settings that remember the position and size of the main emulator window doing this script meant the main window was now literally stuck here in fullscreen with no top or menu bar or adjustable borders. literally, stuck. cannot move or adjust on subsequent launches. Even restarting your PC will not reset this lol what a pickle I got myself in here....I had to rename my "user" folder so it would repopulate and reset on next launch to default settings. Then close the emulator, delete the "new" user folder and rename the "original" user folder back to "user".....then I was back in business as normal. So maybe not a good application to use it for Dolphin, but this would surely be a handy script for some exotic challenges for some users!

Link to comment
Share on other sites

  • 3 weeks later...

Because I'm feeling OCD, I'm going through my emulators and trying to fill in the various pause menu AHK commands.  At the moment, I'm trying to see if I can get RESET menu option working for CEMU.  I searched for an existing keyboard shortcut to do this, couldn't find it.

So I started playing with forcing the program to close and reopen...however the best I can do is get it to close, cuz I'm a n00b at AHK.  Any ideas on what I should try?

Link to comment
Share on other sites

7 hours ago, kaichou said:

forcing the program to close and reopen...however the best I can do is get it to close, cuz I'm a n00b at AHK

It's not so much because your unfamiliar with AutoHotkey, it's because that's as much as you're going to able to do.  "close".

When an emulator has a built-in Reset feature, the emulator stays active while resetting.  As in, it doesn't completely exit then restart.

If you were to add AHK code to the Reset Game Script section of your CEMU emulator (or any emulator for that matter) that closes, then restarts then emulator, you'll have a couple issues.

  1. When your script goes to restart the emulator, there is no viable way to tell it to restart using the same ROM you originally launched with.
  2. This is the big one... When LB/BB sees the emulator close, ALL scripts are abandoned.  So even though your script might 'say' WinClose CEMU... Run CEMU..., when executed through LB/BB, it will never see the latter half.

And even if those weren't issues, it's probably just as easy to exit and then restart the game, normally.  

Link to comment
Share on other sites

  • 5 weeks later...

How would I send a keyboard press whenever a controller button is pressed?  I'd like to add it to an emulator to send the right shift key whenever I press Select on the Xbox controller. I'm pulling my hair out trying to figure out why insert coin doesn't work for some games in MAME/FBNeo and this would be a quick fix.

After reviewing the auothotkey docs, something close to this?

Joy7::         
Send {rshift}
Return

Except this doesn't work (7 the Select button # for me) and not sure on the formatting of the right shift key...

Edited by drw4013
Link to comment
Share on other sites

1 hour ago, drw4013 said:

After reviewing the auothotkey docs, something close to this?

Joy7::         
Send {rshift}
Return

Except this doesn't work (7 the Select button # for me) and not sure on the formatting of the right shift key...

Try this:

1Joy7::
Send, {RShift}

Basically just added a "1" in front of the controller.  

The , (comma) after "Send" and the upper/lower case letters for "RShift" are more for "proper syntax".  The "Return" at the end isn't required because it is implied.  Unless this code is in the middle of a bunch of other code.

 

Depending on which emulator you're using, you may need to 'exaggerate' the key press:

SetKeyDelay, 0, 50

1Joy7::
Send, {RShift}

Which is the same as 

1Joy7::
Send, {RShift down}
Sleep 50
Send, {RShift up}

 

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, JoeViking245 said:

Try this:

1Joy7::
Send, {RShift}

Basically just added a "1" in front of the controller.  

The , (comma) after "Send" and the upper/lower case letters for "RShift" are more for "proper syntax".  The "Return" at the end isn't required because it is implied.  Unless this code is in the middle of a bunch of other code.

 

Depending on which emulator you're using, you may need to 'exaggerate' the key press:

SetKeyDelay, 0, 50

1Joy7::
Send, {RShift}

Which is the same as 

1Joy7::
Send, {RShift down}
Sleep 50
Send, {RShift up}

 

Thanks....neither of those are working but that could be the same original issue with these games. I will need to test with some other keys to verify it works first before trying to fix this insert coin issue.

Link to comment
Share on other sites

8 minutes ago, drw4013 said:

could be the same original issue with these games

You may could just try {Shift}.  Also, try pressing all your buttons, including joystick 'buttons'.  Just in case. ;)  Could you reassign the insert coin (in the emulator) to something that's not a "modifier key"?  Usually it's "5" for player one and "6" for player 2.

  • Thanks 1
Link to comment
Share on other sites

On 8/30/2022 at 5:36 PM, JoeViking245 said:

You may could just try {Shift}.  Also, try pressing all your buttons, including joystick 'buttons'.  Just in case. ;)  Could you reassign the insert coin (in the emulator) to something that's not a "modifier key"?  Usually it's "5" for player one and "6" for player 2.

I figured it out partially - Xbox One controllers won't work with AutoHotkey without the XInput dll.  I got it here: https://www.dropbox.com/s/3ky3wx5stj0uoj9/XInput.ahk?dl=0

I am testing that outside of LB, and it works when I drop in a sample code from here: https://www.autohotkey.com/board/topic/35848-xinput-xbox-360-controller-api/

So, at least the controller will work with AHK now...but unfortunately I don't know how to use XInput to simply send a keypress from a controller button.   don't see any simple examples.  Not sure if I use the constant

XINPUT_GAMEPAD_BACK             := 0x0020

or if I need to use

_XInput_GetState

etc.

Edited by drw4013
Link to comment
Share on other sites

On 8/30/2022 at 4:32 PM, drw4013 said:

How would I send a keyboard press whenever a controller button is pressed?  I'd like to add it to an emulator to send the right shift key whenever I press Select on the Xbox controller. I'm pulling my hair out trying to figure out why insert coin doesn't work for some games in MAME/FBNeo and this would be a quick fix.

After reviewing the auothotkey docs, something close to this?

Joy7::         
Send {rshift}
Return

Except this doesn't work (7 the Select button # for me) and not sure on the formatting of the right shift key...

Hi there @drw4013 I think you are trying to do something that is more or less impossible with AHK. I've looked into this quite a bit myself and never got anything worth while working as far as using AHK to remap xinput style controllers! Key word here is XINPUT! AHK seems to have for the last several years not been able to do what you are trying to accomplish. All Xbox brand or third party Xbox type controllers are going to be XINPUT rather than DINPUT. I cannot confirm if AHK can work at all or better with DINPUT but it may work with DINPUT style controllers in the method you're employing here in your script.

 

When I want to remap my Xbox controllers I use a program like GlovePIE or UCR, these can read xinput for the input, therefore allows you to make the output to something like the keyboard, exactly what you're after! I would have suggested virtualcontroller here too but I realized recently it only reads DINPUT for input. I didn't notice this before because it seems to take an xinput button and put it into the program as a dinput button....but then I found out the output never happens in those cases since it really can only read dinput. virtualcontroller does work fine for DINPUT controllers though. antimicro might be another option, I checked it out after seeing users talk about it here on this forum. I liked it enough I never deleted it after testing, but I admit I cannot remember if it reads xinput for input (like GlovePIE and UCR), or only could use xinput for output? (like virtualcontroller)

 

Here is a couple pages I found a while back that led me to finally wave the white flag and conclude this just ain't happening with AHK and xinput. All the posts I came across there were some ppl saying it works, from posts a decade ago lol, anyone recently is going "hey this isn't working anymore!?!"

https://www.autohotkey.com/boards/viewtopic.php?t=61326

https://www.autohotkey.com/board/topic/35848-xinput-xbox-360-controller-api/page-4

 

@JoeViking245, or anyone at that, please correct me here if I am off in left field on my understanding of AHK and xinput. I would love the ability to do this AHK, so if it is possible, please guide me on some setup steps.

Link to comment
Share on other sites

7 minutes ago, drw4013 said:

I figured it out partially - Xbox One controllers won't work with AutoHotkey without the XInput dll.  I got it here: https://www.dropbox.com/s/3ky3wx5stj0uoj9/XInput.ahk?dl=0

I maybe I got the controller's rumble to work with that example you mentioned too, but I def never got any actual button remapping work. Something seems so fishy about this because it's not like there is a lack of interest in it, yet there seems to be such poor documentation and discussion surrounding it. If ppl found a fix and workaround to use current AHK version on current/modern OS versions, I would think there would be more forums posts and discussions around such a topic.

Link to comment
Share on other sites

@drw4013 @skizzosjt  If Windows sees your controller, you shouldn't have any issues with AHK detecting it.  With it plugged in and on, press Win + R on your keyboard, type "joy.cpl" (without quotes) and press enter.  

image.png.58e7a598faaedb2961a39c53a334d9c9.png

 

Here's a little ditty from the AHK Docs that talks about remapping controllers.  Remapping a Joystick to Keyboard or Mouse | AutoHotkey

Note that remapping via AHK is one-way.  That is, you can setup a hotkey to detect a controller button press (joy stick, d-pad and even z-trigger) and remap that to send a keyboard input (or do some other task).  But, via AHK you can't setup a hotkey that will send a controller button-press.

; Good
1Joy1::
MsgBox, you pressed button 1 on your controller

; Not good (pressing Alt+a will not "press" button 1
!a::
Send, 1joy1

Test the "Good" one outside of LaunchBox like you did the other.  You don't need XInput.dll.  It should just work.  If you read the Doc from the link above, you'll notice their examples don't use the preceding 1 in Joy1.  That 1st "1" is denoting controller #1.  If you have more that 1 controller plugged in and it doesn't work, you may be holding controller #2.  Myself, I only have 1 controller to test with.

Also note that button numbering may vary between emulators.  Example, the Start button may be "7" in one emulator but "8" in another.

Now, if you're trying to get your script to work in a Windows game, Steam or some variant there-of, that could be a whole 'nother issue.  And not a good one, I might add.  They can usually be a right PITA.

 

But back to your original issue... "insert coin doesn't work for some games in MAME/FBNeo".  If MAME (I'm assuming stand-alone MAME) is accepting your other controller inputs, it surely will accept one for Coin Input.  But if it (coin input) works in some games and not others, chances are you have a cfg or ini file associated with that (those) game(s) that's overriding the coin input.  The 'fix' is to get it setup properly in MAME.  Right-Shift is a very odd coin input for MAME.  Also SendKey to MAME can at times be hit-or-miss.  If you're intent on 'fixing' it with an AHK script, you will need to use the one that has the sleep timer ("Sleep, 50") in it between key_down and key_up.  Or it definitely will never work.

image.png

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