Jump to content
LaunchBox Community Forums

AHK Scripts with X-Input Bluetooth Controller


ColinA

Recommended Posts

Dear All,

I hope it's OK to post this question here. I have done something of a search through this forum but can't quite find what I'm looking for: in brief, when connecting my (8BitDo) controller in D-input mode to Windows 11 PC I'm able to write and execute simple AHK scripts in Launchbox enabling exit/closure of emulators via defined button presses (in this case button 'Y' and 'X' on the controller). However, I've found when using X-input this isn't possible (which I believe is due Windows 10/11 requiring AHK to be the 'active' application to work). I'd much prefer to use X-input (over D-input) because it allows for controller rumble that I don't think is supported by D-input.

Searching on the internet I was able to find XInput.ahk (by Lexikos) that appears to circumvent this restriction. After much tinkering on my part (I'm not very tech-savvy) I was able to use the provided scripts to get my X-input connected controller to vibrate when pressing the left/right trigger, regardless if AHK was the 'active' application. However, I can't work out how to update my D-input script to utilise XInput.ahk with what I wish to do. For example, the following script works to (1) initiate closure of the Citra emulator and (2) 'press' keyboard 'Y' to confirm full closure when using controller connected via D-input:

$Joy4:: ;you have to press $Joy5 first
If !GetKeyState("Joy5")
return
{
   WinClose, ahk_exe {{{StartupEXE}}}
   Sleep, 200
   Send {y}
}
return

Would anyone know how to rewrite this script, using XInput.ahk, so that it does the same process for a controller connected via X-input? I've made several attempts but am struggling to get things to work.

Thanks very much for any guidance or help 🙂

Link to comment
Share on other sites

59 minutes ago, ColinA said:

Dear All,

I hope it's OK to post this question here. I have done something of a search through this forum but can't quite find what I'm looking for: in brief, when connecting my (8BitDo) controller in D-input mode to Windows 11 PC I'm able to write and execute simple AHK scripts in Launchbox enabling exit/closure of emulators via defined button presses (in this case button 'Y' and 'X' on the controller). However, I've found when using X-input this isn't possible (which I believe is due Windows 10/11 requiring AHK to be the 'active' application to work). I'd much prefer to use X-input (over D-input) because it allows for controller rumble that I don't think is supported by D-input.

Searching on the internet I was able to find XInput.ahk (by Lexikos) that appears to circumvent this restriction. After much tinkering on my part (I'm not very tech-savvy) I was able to use the provided scripts to get my X-input connected controller to vibrate when pressing the left/right trigger, regardless if AHK was the 'active' application. However, I can't work out how to update my D-input script to utilise XInput.ahk with what I wish to do. For example, the following script works to (1) initiate closure of the Citra emulator and (2) 'press' keyboard 'Y' to confirm full closure when using controller connected via D-input:

$Joy4:: ;you have to press $Joy5 first
If !GetKeyState("Joy5")
return
{
   WinClose, ahk_exe {{{StartupEXE}}}
   Sleep, 200
   Send {y}
}
return

Would anyone know how to rewrite this script, using XInput.ahk, so that it does the same process for a controller connected via X-input? I've made several attempts but am struggling to get things to work.

Thanks very much for any guidance or help 🙂

Why are you using an AHK script to close the emulator? You mentioned Citra in your post, LB/BB can natively close a game launched by pretty much all emulators without needing an AHK. Just map the buttons in the LB and BB settings. Xinput would not be an issue. 

In LB tools under controller mapping just bind both buttons you want pressed to the "Exit" command. Select the "Exit" option and hit both buttons at the same time. 

In BB settings you will bind a "hold" button and then bind the second button to the option for "Close Active Window". 

Link to comment
Share on other sites

Thanks very much for your reply and help Retro808, I should have added that I'd already tried the controller mapping functions in both LB and BB but found they only worked for about 50% of the emulators I'm using. For example, even if a controller button combo does initiate shutdown of Citra, a pop up box always asks if I want to shut down the game and I need to press 'y' on the keyboard and I'm trying to have a setup that only uses a controller without the need of a keyboard. In addition,  I can't seem to get either Dolphin or Cemu to close at all using controller mapped buttons in either LB/BB? Finally, some emulators don't open full-screen (even though I have already set them up individually) and using a controller button combo is really useful to initiate that.

So, with these issues in mind, I decided to write AHK scripts and had success at first with D-input but not X-input as described above. However, there is a good chance I'm not using the controller mapping function properly (as I'm quite new to LB/BB) but, so far as I can see, I believe I'm doing everything correctly?

Link to comment
Share on other sites

If you are being asked to confirm exit then you need to open the emulator and change that setting. Some emulators in their options will have a setting. Open Citra exe and click on >Emulation >Configure. In the General tab uncheck  “Confirm Exit” or similar. 

LB/BB controller automation for exit will send some common close commands. So it will try Escape, Alt+F4 and a few others. If you are having some issues try a simple AHK like below. Many of us use one of the 8bitdo controllers and Xinput works fine.

Dolphin might be one of those troublesome ones. I just checked and I have the script below in my Dolphin set-up. Make sure you are putting the AHK in the "Running Script" tab. The "Exit Script tab is for exiting from the Pause Menu. 

The dollar sign may not be needed so try with or without it. 

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

For Cemu I believe it needs Alt+F4 to exit. So try this one. 

ESC::
{	
    SetTitleMatchMode, 2
    WinWaitActive, Cemu
    Send !{f4}    			
}

 

Link to comment
Share on other sites

Hi Retro808, thanks for your reply, which is much appreciated. I'm now away for the weekend, so making a quick reply, but intend to try out what you suggest at the start of next week. I'll post back but with your help things are starting to make more sense,  so hopefully I can get LB/BB set-up as planned. Thanks again 🙂

Link to comment
Share on other sites

As an update, thanks again for your help Retro808. I've managed to get various emulators to open fullscreen automatically and then exit using X-input button combo that I have assigned. Brilliant and just what I was hoping to achieve. Time to explore different BB themes 😀

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