Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

1 minute ago, jayjay said:

Xbox 360 home button is vk07sc000 in ahk. Im lead to believe its also the same for XB1 controller. But haven't tested myself...

Hmm. I'll give that a try. The test script has never shown anything for me when I press the home button on either a 360 or One controller.

Link to comment
Share on other sites

2 minutes ago, Zombeaver said:

Hmm. I'll give that a try. The test script has never shown anything for me when I press the home button on either a 360 or One controller.

Iv got the wired 360 controller. Dont know if that will make a difference, it shouldn't do....right?.

 

But ahk wont recognise the home button being held down for X amount of seconds. And if I remember correctly wouldnt play well with key wait commands. But still useful to have the extra button. 

Link to comment
Share on other sites

1 minute ago, jayjay said:

Iv got the wired 360 controller. Dont know if that will make a difference, it shouldn't do....right?.

It shouldn't. It's never made any difference for me between wired and wireless but that's with the caveat that I use the USB dongles for both 360 and One controllers; and I can confirm that AHK does have some issues with recognizing inputs when using a One controller over bluetooth specifically. Last time I tried that, the test script didn't recognize any inputs when it was over bluetooth but worked fine with the wireless dongle.

3 minutes ago, jayjay said:

But ahk wont recognise the home button being held down for X amount of seconds. And if I remember correctly wouldnt play well with key wait commands.

Hmm, very weird...

4 minutes ago, jayjay said:

But still useful to have the extra button. 

Yeah, definitely. One more button is one more button.

Link to comment
Share on other sites

In the test script you posted it says...

 

; July 6, 2005: Added auto-detection of joystick number.
; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of
; detecting whether the joystick is connected.  Some joysticks are
; gamepads and don't have even a single axis.

 

It may be a little out dated now. But im not sure on that. Dont know if its been updated since 2005.

Edited by jayjay
Link to comment
Share on other sites

8 hours ago, Dane said:

Hi, I use the following to close MAME:


$4::
{
    Process, Close, {{{StartupEXE}}}
}

I am wanting to add the option to close it via the home-button on the PS4 controller as well as the '4' on the keyboard. Would someone be so kind as to show me how? Thank you in advance.

A program called Controller Companion on Steam is able to map functions to the XBOX 360 Guide Button. I have Controller Companion and Xpadder running at the same time and I use CC to map Quit Functions to the Guide button and Xpadder for everything else (Xpadder can't map the Guide Button).

I don't know about the PS4 controller but maybe it is something you could look at it if you find no other way. http://controllercompanion.com/

Link to comment
Share on other sites

31 minutes ago, Zombeaver said:

Sometimes I would come across something in the docs that wouldn't work correctly. I found that googling "autohotkey blah blah blah" became more useful than the docs, probably more me being crap than anything else.  But that links pov section was the final piece I needed to ditch xpadder and map everything with ahk for my 360 controller only set up. :)

 

I miss playing with ahk more than missing gaming or LB (which doesn't get enough love anymore). Anyway never mind the off topic. Its 9.20pm, way past my bedtime. Growing up, having a job and responsibility is the worse human invention ever created. Take it easy mate.

Link to comment
Share on other sites

12 minutes ago, jayjay said:

probably more me being crap than anything else.

You ain't crap bro. You helped me out with that script a couple of months ago for my conundrum with PC Sega Rally 2 (The check if process running script) which helped me a great deal. Why are you not playing with AHK anymore and the sombre tone in your posts? wassup?

Edited by JamesBond@ge
Link to comment
Share on other sites

7 hours ago, JamesBond@ge said:

A program called Controller Companion on Steam is able to map functions to the XBOX 360 Guide Button. I have Controller Companion and Xpadder running at the same time and I use CC to map Quit Functions to the Guide button and Xpadder for everything else (Xpadder can't map the Guide Button).

I don't know about the PS4 controller but maybe it is something you could look at it if you find no other way. http://controllercompanion.com/

Thank you, it looks really good. I do use the PS4 controller home-button for closing Retroarch so mapping it via Controller Companion might have the potential to mess with that? Although if it did I suppose I could just redo the newly mapped button in Retroarch. I will definitely give it a try, thanks again.

Link to comment
Share on other sites

If you are using a standalone MAME, there won't be any conflict.

CC automatically detects the running process of your choosing eg. "mame.exe" "mame64.exe" and then launches your profile silently in the background (and exits it when you close the program).

Infact, you can put multiple exe's in one profile "mame64.exe" "mame.exe" "mameui.exe" "mameforjames.exe" "mameforrainysundays.exe" "dontmamemeyoubastard.exe" so you get them all covered. I have 140 MUGEN games that have different named exe's. I copied all the names of the exe's into one profile (it took a while lol) which has mapped Alt + F4 to my Guide button.

It's a good little program. Well worth the small amount of money. It is not tied to Steam either and can run independently. Their site says it is compatible with PS controllers. I don't know about PS4 though as that is too new for me lol. (I'm not affiliated with this program btw :D)

Edited by JamesBond@ge
  • Like 1
Link to comment
Share on other sites

50 minutes ago, JamesBond@ge said:

If you are using a standalone MAME, there won't be any conflict.

CC automatically detects the running process of your choosing eg. "mame.exe" "mame64.exe" and then launches your profile silently in the background (and exits it when you close the program).

Infact, you can put multiple exe's in one profile "mame64.exe" "mame.exe" "mameui.exe" "mameforjames.exe" "mameforrainysundays.exe" "dontmamemeyoubastard.exe" so you get them all covered. I have 140 MUGEN games that have different named exe's. I copied all the names of the exe's into one profile (it took a while lol) which has mapped Alt + F4 to my Guide button.

It's a good little program. Well worth the small amount of money. It is not tied to Steam either and can run independently. Their site says it is compatible with PS controllers. I don't know about PS4 though as that is too new for me lol. (I'm not affiliated with this program btw :D)

I just bit the bullet and threw the whopping $3 down for it. It took me a bit to work out I had to have DS4 open for it to work but I added both DS4 and C.C. to open upon windows starting up. I have not mapped anything yet but am already very impressed with what I have seen. Thanks for the info.

Link to comment
Share on other sites

9 minutes ago, neil9000 said:

Yeah controller companion is great, you just need to add a new profile and associate it with a .exe then set all the buttons you want and apply. It will then auto load that profile everytime that .exe is launched, and close that profile when the .exe exits.

There is something really wrong with the world when a disgusting abomination like the seventh Fast and the Furious film won the People's Choice Awards for Favorite Action Movie and something awesome like Controller Companion does not receive an equivalent accolade.

Edited by Dane
  • Haha 1
Link to comment
Share on other sites

4 hours ago, thedevilsjester said:

Has anyone played with getting an AutoHotKey script to map an analog stick to the mouse for certain emulators like DeSmuME and Citra?

I just created a profile for PPSSPP with Controller Companion and without having to do anything else it automatically made the two analogue sticks on my PS4 controller operate as a mouse where before they were not. I am not the best at all this stuff, but would this be an option for you?

Link to comment
Share on other sites

On 4/8/2018 at 12:02 AM, neil9000 said:

Yeah controller companion is great, you just need to add a new profile and associate it with a .exe then set all the buttons you want and apply. It will then auto load that profile everytime that .exe is launched, and close that profile when the .exe exits.

Just wanted to say thank you as I figured this out tonight and it works like a charm. It has definitely made my setup that little bit more easy now.

  • Like 1
Link to comment
Share on other sites

10 hours ago, Dane said:

I just created a profile for PPSSPP with Controller Companion and without having to do anything else it automatically made the two analogue sticks on my PS4 controller operate as a mouse where before they were not. I am not the best at all this stuff, but would this be an option for you?

Beware of using any remapping tools when running emulators because they add considerable latency to the controller input.  Usually polling is set to around 10 ms so all of your input is delayed by 10 ms on top of what the emulators already do (this is roughly 10x the input latency that emulators strive for).  You can often configure the polling interval to be smaller, but the more often you poll, the more CPU it eats up.  You might not realize that this is why that jump is always just a little bit too late, or that you could have sworn you dodged that shot, it could be your timing, or it could be the additional latency of a remapping application.

My personal use case (the rare but required input on some DS and 3DS games) does not require any reasonable input latency, but if you are mapping/remapping inputs it will definitly slow the input responsiveness of your game.

I already know about additional apps that can achieve this, I used them prior to installing LaunchBox because of the Esc/Alt+F4 requirements to exit some of the emulators.  LaunchBox has eliminated the need to have yet another application polling for input in the background for most of my use cases, I am just hoping that it can be used to remap an analog stick to the mouse, so it can do all of the remapping I need.

Edited by thedevilsjester
Link to comment
Share on other sites

I use this to control mouse with 360 controller. Not my work. Cant remember where I got it, might be in the docs.

 

Uses right analogue to control mouse:

#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.
SetTimer, WatchPOV, 5
; Using a Joystick as a Mouse
; http://www.autohotkey.com
; This script converts a joystick into a three-button mouse.  It allows each
; button to drag just like a mouse button and it uses virtually no CPU time.
; Also, it will move the cursor faster depending on how far you push the joystick
; from center. You can personalize various settings at the top of the script.

; Increase the following value to make the mouse cursor move faster:
JoyMultiplier = 0.30

; Decrease the following value to require less joystick displacement-from-center
; to start moving the mouse.  However, you may need to calibrate your joystick
; -- ensuring it's properly centered -- to avoid cursor drift. A perfectly tight
; and centered joystick could use a value of 1:
JoyThreshold = 9

; Change the following to true to invert the Y-axis, which causes the mouse to
; move vertically in the direction opposite the stick:
InvertRAxis := false

; Change these values to use joystick button numbers other than 1, 2, and 3 for
; the left, right, and middle mouse buttons.  Available numbers are 1 through 32.
; Use the Joystick Test Script to find out your joystick's numbers more easily.
ButtonLeft = 1
ButtonRight = 2
ButtonMiddle = 3

; If your joystick has a POV control, you can use it as a mouse wheel.  The
; following value is the number of milliseconds between turns of the wheel.
; Decrease it to have the wheel turn faster:
WheelDelay = 250

; If your system has more than one joystick, increase this value to use a joystick
; other than the first:
JoystickNumber = 1

; END OF CONFIG SECTION -- Don't change anything below this point unless you want
; to alter the basic nature of the script.

JoystickPrefix = %JoystickNumber%Joy
Hotkey, %JoystickPrefix%%ButtonLeft%, ButtonLeft
Hotkey, %JoystickPrefix%%ButtonRight%, ButtonRight
Hotkey, %JoystickPrefix%%ButtonMiddle%, ButtonMiddle

; Calculate the axis displacements that are needed to start moving the cursor:
JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold
if InvertRAxis
	RAxisMultiplier = -1
else
	RAxisMultiplier = 1

SetTimer, WatchJoystick, 10  ; Monitor the movement of the joystick.

GetKeyState, JoyInfo, %JoystickNumber%JoyInfo
IfInString, JoyInfo, P  ; Joystick has POV control, so use it as a mouse wheel.
	SetTimer, MouseWheel, %WheelDelay%

return  ; End of auto-execute section.


; The subroutines below do not use KeyWait because that would sometimes trap the
; WatchJoystick quasi-thread beneath the wait-for-button-up thread, which would
; effectively prevent mouse-dragging with the joystick.

ButtonLeft:
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left,,, 1, 0, D  ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 10
return

ButtonRight:
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, right,,, 1, 0, D  ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 10
return

ButtonMiddle:
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, middle,,, 1, 0, D  ; Hold down the right mouse button.
SetTimer, WaitForMiddleButtonUp, 10
return

WaitForLeftButtonUp:
if GetKeyState(JoystickPrefix . ButtonLeft)
	return  ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForLeftButtonUp, off
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left,,, 1, 0, U  ; Release the mouse button.
return

WaitForRightButtonUp:
if GetKeyState(JoystickPrefix . ButtonRight)
	return  ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
MouseClick, right,,, 1, 0, U  ; Release the mouse button.
return

WaitForMiddleButtonUp:
if GetKeyState(JoystickPrefix . ButtonMiddle)
	return  ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForMiddleButtonUp, off
MouseClick, middle,,, 1, 0, U  ; Release the mouse button.
return

WatchJoystick:
MouseNeedsToBeMoved := false  ; Set default.
SetFormat, float, 03
GetKeyState, joyu, %JoystickNumber%JoyU
GetKeyState, joyr, %JoystickNumber%JoyR
if joyu > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	DeltaU := joyu - JoyThresholdUpper
}
else if joyu < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaU := joyu - JoyThresholdLower
}
else
	DeltaU = 0
if joyr > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	DeltaR := joyr - JoyThresholdUpper
}
else if joyr < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaR := joyr - JoyThresholdLower
}
else
	DeltaR = 0
if MouseNeedsToBeMoved
{
	SetMouseDelay, -1  ; Makes movement smoother.
	MouseMove, DeltaU * JoyMultiplier, DeltaR * JoyMultiplier * RAxisMultiplier, 0, R
}
return

MouseWheel:
GetKeyState, JoyPOV, %JoystickNumber%JoyPOV
if JoyPOV = -1  ; No angle.
	return
if (JoyPOV > 31500 or JoyPOV < 4500)  ; Forward
	Send {WheelUp}
else if JoyPOV between 13500 and 22500  ; Back
	Send {WheelDown}
return

WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
if POV < 0   ; No angle to report
    KeyToHoldDown =
else if POV > 31500                 ; 315 to 360 degrees: Forward
    KeyToHoldDown = Up
else if POV between 0 and 4500      ; 0 to 45 degrees: Forward
    KeyToHoldDown = Up
else if POV between 4501 and 13500  ; 45 to 135 degrees: Right
    KeyToHoldDown = Right
else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
    KeyToHoldDown = Down
else                                ; 225 to 315 degrees: Left
    KeyToHoldDown = Left

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
;traytip,,%keyToHoldDown%,1
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return

 

It also does other stuff like dpad to mouse wheel etc. I was gonna post the script I use up, it uses the left analogue but I cant find it. To change it to left analogue you would need to change...

joyr = joyx

deltaR = deltaX

joyu = joyy

deltaU = deltaY

or maybe its...

joyr = joyy

etc

etc

Cant quite remember. You will have to have a play with it. Also not sure if it will work as intended through LB.

 

Edited by jayjay
Link to comment
Share on other sites

1 hour ago, jayjay said:

I use this to control mouse with 360 controller. Not my work. Cant remember where I got it, might be in the docs.

...

Cant quite remember. You will have to have a play with it. Also not sure if it will work as intended through LB.

I saw a similar one on a website for AutoHotKeys but I was not able to get it running through LaunchBox (I am not familiar enough with the AutoHotKeys syntax and variable expansion).  I am curious if anyone has gotten similar working with LaunchBox's AutoHotKey script area as it would just make everything so much simpler to only deal with LaunchBox.

Link to comment
Share on other sites

On 10/04/2018 at 8:44 PM, thedevilsjester said:

I saw a similar one on a website for AutoHotKeys but I was not able to get it running through LaunchBox (I am not familiar enough with the AutoHotKeys syntax and variable expansion).  I am curious if anyone has gotten similar working with LaunchBox's AutoHotKey script area as it would just make everything so much simpler to only deal with LaunchBox.

JoyMultiplier = 0.30

JoyThreshold = 9

InvertRAxis := false

ButtonLeft = 1
ButtonRight = 2
ButtonMiddle = 3

JoystickNumber = 1

JoystickPrefix = %JoystickNumber%Joy
Hotkey, %JoystickPrefix%%ButtonLeft%, ButtonLeft
Hotkey, %JoystickPrefix%%ButtonRight%, ButtonRight
Hotkey, %JoystickPrefix%%ButtonMiddle%, ButtonMiddle

JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold
if InvertRAxis
	RAxisMultiplier = -1
else
	RAxisMultiplier = 1

SetTimer, WatchJoystick, 10 

GetKeyState, JoyInfo, %JoystickNumber%JoyInfo
IfInString, JoyInfo, P 
	
return

ButtonLeft:
SetMouseDelay, -1
MouseClick, left,,, 1, 0, D
SetTimer, WaitForLeftButtonUp, 10
return

ButtonRight:
SetMouseDelay, -1
MouseClick, right,,, 1, 0, D
SetTimer, WaitForRightButtonUp, 10
return

ButtonMiddle:
SetMouseDelay, -1
MouseClick, middle,,, 1, 0, D
SetTimer, WaitForMiddleButtonUp, 10
return

WaitForLeftButtonUp:
if GetKeyState(JoystickPrefix . ButtonLeft)
	return

SetTimer, WaitForLeftButtonUp, off
SetMouseDelay, -1
MouseClick, left,,, 1, 0, U
return

WaitForRightButtonUp:
if GetKeyState(JoystickPrefix . ButtonRight)
	return

SetTimer, WaitForRightButtonUp, off
MouseClick, right,,, 1, 0, U  ; Release the mouse button.
return

WaitForMiddleButtonUp:
if GetKeyState(JoystickPrefix . ButtonMiddle)
	return

SetTimer, WaitForMiddleButtonUp, off
MouseClick, middle,,, 1, 0, U  ; Release the mouse button.
return

WatchJoystick:
MouseNeedsToBeMoved := false  ; Set default.
SetFormat, float, 03
GetKeyState, joyx, %JoystickNumber%JoyX
GetKeyState, joyy, %JoystickNumber%JoyY
if joyx > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	DeltaX := joyx - JoyThresholdUpper
}
else if joyx < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaX := joyx - JoyThresholdLower
}
else
	DeltaX = 0
if joyy > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	DeltaY := joyy - JoyThresholdUpper
}
else if joyy < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaY := joyy - JoyThresholdLower
}
else
	DeltaY = 0
if MouseNeedsToBeMoved
{
	SetMouseDelay, -1  ; Makes movement smoother.
	MouseMove, DeltaX * JoyMultiplier, DeltaY * JoyMultiplier * RAxisMultiplier, 0, R
}
return

This is the same script as the one I posted above. Except with no dpad or mouse wheel, only has the mouse pointer and 3 buttons. Also uses the left analogue not right. If you need to change anything compare this script with the one above. I tested it and it works through LB.

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