Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

a variation on joystickmouse.ahk - button press boost speed


  • Please log in to reply
No replies to this topic
slambs
  • Guests
  • Last active:
  • Joined: --
for those that would like a little more control over mouse speed
this allows you to set a joystick button to boost the movement speed while the button is pressed. now you dont need to wait while that slow mouse moves across your screen(s), just press the boost button and zoom.

just compare the original with this one to see the modifications

; 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, and/or set the multiplier from your choice of joystick button. You can
; personalize various settings at the top of the script.

; Increase the following value to make the mouse cursor move faster (normal speed):
JoyMultiplier = 0.05

; 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 = 3

; Change these values to use joystick button numbers other than 1, 2, and 3 for
; the left, right, and middle mouse buttons, respectively:
ButtonLeft = 2
ButtonRight = 3
ButtonMiddle = 1

; Use the button bellow to give a quick boost to the mouse movement speed:
MouseSpeedButton = 11

; Increase or decrease the mouse movement speed multiplier to suit - from MouseSpeedButton.
; (faster than normal speed):
MouseMultiplier = 6

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

#SingleInstance

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

; Calculate the axis displacements that are needed to start moving the cursor:
JoyThresholdUpper = 50
JoyThresholdUpper += %JoyThreshold%
JoyThresholdLower = 50
JoyThresholdLower -= %JoyThreshold%

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:
GetKeyState, JoyStateLeft, %JoystickNumber%Joy%ButtonLeft%
if JoyStateLeft = D  ; The button is still, down, so keep waiting.
	return
; 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:
GetKeyState, JoyStateRight, %JoystickNumber%Joy%ButtonRight%
if JoyStateRight = D  ; The button is still, down, so keep waiting.
	return
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
MouseClick, right,,, 1, 0, U  ; Release the mouse button.
return

WaitForMiddleButtonUp:
GetKeyState, JoyStateMiddle, %JoystickNumber%Joy%ButtonMiddle%
if JoyStateMiddle = D  ; The button is still, down, so keep waiting.
	return
; Otherwise, the button has been released.
SetTimer, WaitForMiddleButtonUp, off
MouseClick, middle,,, 1, 0, U  ; Release the mouse button.
return

WatchJoystick:
MoveMouse? = n  ; Set default.
SetFormat, float, 03
GetKeyState, joyx, %JoystickNumber%JoyX
GetKeyState, joyy, %JoystickNumber%JoyY
if joyx > %JoyThresholdUpper%
{
	MoveMouse? = y
	DeltaX = %joyx%
	DeltaX -= %JoyThresholdUpper%
}
else if joyx < %JoyThresholdLower%
{
	MoveMouse? = y
	DeltaX = %joyx%
	DeltaX -= %JoyThresholdLower%
}
else
	DeltaX = 0
if joyy > %JoyThresholdUpper%
{
	MoveMouse? = y
	DeltaY = %joyy%
	DeltaY -= %JoyThresholdUpper%
}
else if joyy < %JoyThresholdLower%
{
	MoveMouse? = y
	DeltaY = %joyy%
	DeltaY -= %JoyThresholdLower%
}
else
	DeltaY = 0
if MoveMouse? = y
{
	DeltaX *= %JoyMultiplier%
	DeltaY *= %JoyMultiplier%
		GetKeyState, joyBstate, Joy%MouseSpeedButton% 
		if joyBstate = D
{
	EnvMult, DeltaX, MouseMultiplier
	EnvMult, DeltaY, MouseMultiplier
}
	SetMouseDelay, -1  ; Makes movement smoother.
	MouseMove, %DeltaX%, %DeltaY%, 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