LaunchBox Community Forums

# Autohotkey script to Open/Close BetterJoy

## Recommended Posts

Pretty much a self explanatory title.

I want to implement an autohotkey script that open/closes BetterJoy when running/closing a game on Dolphin alone.

I use BetterJoy for Dolphin, because it helps me playing Wii games with motion control of my joycons.
But it doesn't work well with other emulators, so I need it to close everytime I close Dolphin, and open again everytime I open Dolphin again.

I've no knowledge of autohotkey scripts. Hope someone can help me.

Edited by otavioraposojr

• Replies 48
• Created

#### Posted Images

So, I would suggest you checking out rocketlauncher. It is overwhelming for beginners, however, it's very powerful. Even if you don't implement it into your lb setup, you can learn how it launches games and with that, this can learn a lot about using AHK. I'm not near my setup right now to type out a test script for you but you can create a blank AHK script and run it, from there you can right click on it in the system tray and go to WindowSpy. Then launch your game in dolphin, it will give you the window title that's needed to create a launcher script. If you want, you can pm me and I'll try to get you straightened out, I see a lot of trial and error with this ?.

##### Share on other sites

I strongly would not recommend rocketlauncher. As you said, it is overwhelming for beginners. And by now very out of date and interferes with the working of LaunchBox. The few advantages rocketlauncher has over LaunchBox I could live without.

Go to Tools > Manage Emulators > Dolphin >  Running AutoHotKey Script tab. Add:

Run, "path\to\BetterJoyForCemu.exe"

$Esc:: { WinClose, ahk_exe BetterJoyForCemu.exe } *By "path\to\BetterJoyForCemu.exe" of course I mean de path to the BetterJoyForCemu folder and executable.* Edited by Koroth ##### Link to comment ##### Share on other sites I don't use RocketLauncher, so I'm not in a position to say anything good or bad about it other than what I'd get out of it isn't worth the pain it is to A) figure out how to set it up, then B) actually get it setup, and lastly C) have it actually work. I think @Koroth's script is the cleanest way to do this. I don't know if BetterJoy needs to be running BEFORE Dolphin starts, but as I think about it, it would make sense that the Running AutoHotkey Script setup for the emulator would execute before having the emulator launch the game. Koroth, have you personally used this as the Running AutoHotkey Script for starting (and stopping) BetterJoy? (you didn't say and I know nothing about BetterJoy ) ##### Link to comment ##### Share on other sites 14 minutes ago, JoeViking245 said: Koroth, have you personally used this as the Running AutoHotkey Script for starting (and stopping) BetterJoy? (you didn't say and I know nothing about BetterJoy ) I tested this script with starting and stopping and that worked as it should. On my computer the BetterJoy windows appears about 1 sec. before Dolphin's. However I don't own any Nintendo controllers, so I can't verify BetterJoy actually works. ##### Link to comment ##### Share on other sites Just did a little testing with this and it seems the Escape hotkey here messes with closing the emulator. For my tests I used notepad.exe instead BetterJoy. The Running AutoHotkey Script does indeed load BEFORE LaunchBox has the emulator run the game. But when I hit Escape, Notepad (in my sample test) closes, but Dolphin (also tested with MAME) does not. When I hit Escape again, it still doesn't close. Verified Dolphin had focus and still wouldn't close with Escape. So plan "B" (verified to work with Notepad and Dolphin) run, notepad.exe$esc::
{
WinClose, ahk_exe dolphin.exe
}

@otavioraposojr  Just replace "notepad.exe" (2 spots) with your BetterJoy executable filename ("BetterJoyForCemu.exe"?) and put this is the Running AutoHotkey Script tab as Koroth said.

run, "full\path\to\BetterJoyForCemu.exe"

##### Share on other sites

@Koroth Just use the <> (code) option in the text box when you post a response. Right above the text box you will see the brackets. That's for posting code text.

##### Share on other sites

3 minutes ago, Retro808 said:

@Koroth Just use the <> (code) option in the text box when you post a response. Right above the text box you will see the brackets. That's for posting code text.

Thank you! (BTW, this was a test.)

##### Share on other sites

@JoeViking245 I've a problem with the "esc" solution. I use Big Box, and I close the games not by using the esc key on computer keyboard, but by pressing the share button on my Nintendo Pro Controller (configured to "Close Active Window" in Big Box options). I use this as a "universal closer" to all emulators, because it makes everthing much easier.

I tested the script and BetterJoy will not close precisely because I'm not closing using the esc key. Any way around that?

Edited by otavioraposojr
##### Share on other sites

2 hours ago, otavioraposojr said:

"Close Active Window" in Big Box options

That's an interesting way to close an emulator.  Well, I should say that's new to me.  But if it works, great!

Any chance you tested it by pressing Escape on your keyboard?  Just curious.  Because if that doesn't work, neither will the following.  And using Escape (just for initial testing purposes) makes it easier to troubleshoot if there are issues.

Similar to Esc:: before, but using the joy button

run, "full\path\to\BetterJoyForCemu.exe"

1Joyx::
{
WinClose, ahk_exe BetterJoyForCemu.exe
WinClose, ahk_exe dolphin.exe
}

Replace the "x" in "1Joyx::" with the button number corresponding to the "Close Active Window" button you setup in BigBox.  (It should show you the button 'number').

For example, if it says 'button 12', you'd use "1Joy12::".

##### Share on other sites

7 hours ago, otavioraposojr said:

@JoeViking245 I've a problem with the "esc" solution. I use Big Box, and I close the games not by using the esc key on computer keyboard, but by pressing the share button on my Nintendo Pro Controller (configured to "Close Active Window" in Big Box options). I use this as a "universal closer" to all emulators, because it makes everthing much easier.

I tested the script and BetterJoy will not close precisely because I'm not closing using the esc key. Any way around that?

As long as the program uses "Escape to close, using Escape command in AHK should still work even though you have bound a button to "Close Active Window". How LB/BB controller automation works is LB/BB uses the button you mapped to send "Escape" to close the active window. LB waits a few seconds and if LB is not in focus (meaning the emulator has not closed) it will then send "Alt+F4" and try again. Jason even put in some of the unique close command like Ctrl+F9 for DOSBox. Now, it some emulators may be a little more stubborn and need tweaking.

It could be possible BetterJoy does not like "Escape" to close. If you just open BetterJoy and hit Escape does it close? It may prefer Alt+F4.

##### Share on other sites

3 hours ago, Retro808 said:

It could be possible BetterJoy does not like "Escape" to close. If you just open BetterJoy and hit Escape does it close? It may prefer Alt+F4.

@Retro808 In this case "Escape" isn't used to close BetterJoy. "Escape" just sends the autohotkey "WinClose" command, which closes BetterJoy.

@otavioraposojr BetterJoy has a checkbox to "Start in Tray". Make sure that is unchecked. If you did, start the game and double click on the BetterJoy tray icon and uncheck. Autohotkey's "WinClose" command does not work with apps that solely reside in the system-tray. (Usually they need to be force closed.)

##### Share on other sites

13 minutes ago, Koroth said:

@Retro808 In this case "Escape" isn't used to close BetterJoy. "Escape" just sends the autohotkey "WinClose" command, which closes BetterJoy.

Good point. I did not read the whole thread, just the post I replied to. That's what I get for partially reading.

##### Share on other sites

Thank you for the replies. I tested the script again and it worked with the "esc" solution, even using the button on the joystick. It works even with "Start in Tray" checked. It's all good.

Edited by otavioraposojr
##### Share on other sites

• 3 weeks later...

This is really neat.

Is this possible with Citra and CEMU as well? Basically same principle when launched from big box betterjoy opens and when emulator exits betterjoy closes?

##### Share on other sites

• 3 weeks later...
On 11/12/2020 at 2:12 AM, Koroth said:

I strongly would not recommend rocketlauncher. As you said, it is overwhelming for beginners. And by now very out of date and interferes with the working of LaunchBox. The few advantages rocketlauncher has over LaunchBox I could live without.

Go to Tools > Manage Emulators > Dolphin >  Running AutoHotKey Script tab. Add:

Run, "path\to\BetterJoyForCemu.exe"

$Esc:: { WinClose, ahk_exe BetterJoyForCemu.exe } *By "path\to\BetterJoyForCemu.exe" of course I mean de path to the BetterJoyForCemu folder and executable.* This is working great for me running DS4Windows. I added to the emulator start script. How do I kill the process using AHK when I leave the emulator/exit game? ##### Link to comment ##### Share on other sites 32 minutes ago, Wanderer189 said: This is working great for me running DS4Windows. I added to the emulator start script. How do I kill the process using AHK when I leave the emulator/exit game? Try: $Esc::
{
WinClose, ahk_exe DS4Windows.exe
} 

If that doesn't work try:

$Esc:: { Process, Close, DS4Windows.exe }  ##### Link to comment ##### Share on other sites 4 minutes ago, Koroth said: Try: $Esc::
{
WinClose, ahk_exe DS4Windows.exe
} 

If that doesn't work try:


$Esc:: { Process, Close, DS4Windows.exe }  I tried them both, will I need to edit path for them to match how I am calling it? Run, "D:\Program Files (Portable)\DS4Windows\DS4Windows.exe"$Esc::
{
WinClose, ahk_exe DS4Windows.exe
}

##### Share on other sites

You can close a program by using a window title/class name or a process name. You don't need a full path for that (if I understand you correctly.) Let me know if it works.

## Join the conversation

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

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

×
×
• Create New...