I have created a basic interface driver for my PS2 joystick for Warcraft. Yet the problem is that NONE of my modifier keys are operation while AHK is running and my script is loaded. Did i break something with this code. I started with the code provided in the documentation. Thank you in advance for such an amazing product.
Code:
; Using a PS2 Gamepad Keyboard Mapper
; Made by NecriShiite
;
; Designed for World Of Warcraft
;
; This script specially maps the PS2 Gamepad to the keyboard.
; It remaps each button and joystick to the keyboard. It also
; uses virtually no CPU time. It is recommended to customize
; each of the settings in the config section for your needs.
; ========================BEGIN OF CONFIG SECTION=============================
; Increase the following value to make the mouse cursor move faster:
JoyMultiplier = 0.40
; 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 = 10
; Change these values to use joystick button numbers other than 1, 2, and 3 for
; the left, right, and middle mouse buttons, respectively:
BtnSquare = 4
BtnCross = 3
BtnCircle = 2
BtnTriangle = 1
BtnL2 = 5
BtnR2 = 6
BtnL1 = 7
BtnR1 = 8
; Change these values to specify the newly mapped key you want to use for
; each previously defined button above
SquareKey = Enter
CrossKey = .
CircleKey = Space
TriangleKey = Escape
;R1Key =
;R2Key =
;L1Key =
;L2Key =
; Change these values to specify the newly mapped key you want to use
; the Left joystick on the PS2 Gamepad
JoyLeftKey = Left
JoyRightKey = Right
JoyUpKey = Up
JoyDownKey = Down
; 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 = 100
; If there are multiple joysticks, change this value to another joystick ID
; Look under gaming options in the Control Panel for the correct ID
JoyNum = 1
; Calculate the axis displacements that are needed to start moving the cursor:
JoyUpper = 50
JoyUpper += %JoyThreshold%
JoyLower = 50
JoyLower -= %JoyThreshold%
; =======================END OF CONFIG SECTION================================
#SingleInstance
SetFormat, float, 03 ; Omit decimal points from numbers
GetKeyState, joy_name, %JoyNum%JoyName
Hotkey, %JoyNum%Joy%BtnSquare%, BtnSquare
Hotkey, %JoyNum%Joy%BtnCross%, BtnCross
Hotkey, %JoyNum%Joy%BtnCircle%, BtnCircle
Hotkey, %JoyNum%Joy%BtnTriangle%, BtnTriangle
Hotkey, %JoyNum%Joy%BtnL1%, BtnL1
Hotkey, %JoyNum%Joy%BtnR1%, BtnR1
SetTimer, WatchJoy1, 10 ; Monitor the movement of the Left joystick.
SetTimer, WatchJoy2, 20 ; Monitor the movement of the Right joystick.
GetKeyState, JoyInfo, %JoyNum%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.
BtnSquare:
SetKeyDelay -1
Send, {%SquareKey% down}
SetTimer, WaitForBtnSquareUp, 10
return
BtnCross:
SetKeyDelay -1
Send, {%CrossKey% down}
SetTimer, WaitForBtnCrossUp, 10
return
BtnCircle:
SetKeyDelay -1
Send, {%CircleKey% down}
SetTimer, WaitForBtnCircleUp, 10
return
BtnTriangle:
SetKeyDelay -1
Send, {%TriangleKey% down}
SetTimer, WaitForBtnTriangleUp, 10
return
BtnL1:
SetMouseDelay, -1
MouseClick, left,,, 1, 0, D
SetTimer, WaitForBtnL1Up, 10
return
BtnR1:
SetMouseDelay, -1
MouseClick, right,,, 1, 0, D
SetTimer, WaitForBtnR1Up, 10
return
WaitForBtnSquareUp:
SetKeyDelay -1
GetKeyState, JoyStateSquare, %JoyNum%Joy%BtnSquare%
if JoyStateSquare = D ; Button still down
return
SetTimer, WaitForBtnSquareUp, off
Send, {%SquareKey% up}
return
WaitForBtnCrossUp:
SetKeyDelay -1
GetKeyState, JoyStateCross, %JoyNum%Joy%BtnCross%
if JoyStateCross = D ; Button still down
return
SetTimer, WaitForBtnCrossUp, off
Send, {%CrossKey% up}
return
WaitForBtnCircleUp:
SetKeyDelay -1
GetKeyState, JoyStateCircle, %JoyNum%Joy%BtnCircle%
if JoyStateCircle = D ; Button still down
return
SetTimer, WaitForBtnCircleUp, off
Send, {%CircleKey% up}
return
WaitForBtnTriangleUp:
SetKeyDelay -1
GetKeyState, JoyStateTriangle, %JoyNum%Joy%BtnTriangle%
if JoyStateTriangle = D ; Button still down
return
SetTimer, WaitForBtnTriangleUp, off
Send, {%TriangleKey% up}
return
WaitForBtnL1Up:
GetKeyState, JoyStateL1, %JoyNum%Joy%BtnL1%
if JoyStateL1 = D
return
SetTimer, WaitForBtnL1Up, off
SetMouseDelay, -1
MouseClick, left,,, 1, 0, U
return
WaitForBtnR1Up:
GetKeyState, JoyStateR1, %JoystickNumber%Joy%BtnR1%
if JoyStateR1 = D
return
SetTimer, WaitForBtnR1Up, off
MouseClick, right,,, 1, 0, U
return
WatchJoy1:
SetKeyDelay -1
SetFormat, float, 03
GetKeyState, joyx, %JoyNum%JoyX
GetKeyState, joyy, %JoyNum%JoyY
if joyx > %JoyUpper%
{
Send, {%JoyRightKey% down}
}
else if joyx < %JoyLower%
{
Send, {%JoyLeftKey% down}
}
else
{
Send, {%JoyLeftKey% up}
Send, {%JoyRightKey% up}
}
if joyy > %JoyUpper%
{
Send, {%JoyDownKey% down}
}
else if joyy < %JoyLower%
{
Send, {%JoyUpKey% down}
}
else
{
Send, {%JoyUpKey% up}
Send, {%JoyDownKey% up}
}
return
WatchJoy2:
MoveMouse? = n ; Set default.
SetFormat, float, 03
GetKeyState, joyr, %JoyNum%JoyR
GetKeyState, joyz, %JoyNum%JoyZ
if joyr > %JoyUpper%
{
MoveMouse? = y
DeltaR = %joyr%
DeltaR -= %JoyUpper%
}
else if joyr < %JoyLower%
{
MoveMouse? = y
DeltaR = %joyr%
DeltaR -= %JoyLower%
}
else
DeltaR = 0
if joyz > %JoyUpper%
{
MoveMouse? = y
DeltaZ = %joyz%
DeltaZ -= %JoyUpper%
}
else if joyz < %JoyLower%
{
MoveMouse? = y
DeltaZ = %joyz%
DeltaZ -= %JoyLower%
}
else
DeltaZ = 0
if MoveMouse? = y
{
DeltaR *= %JoyMultiplier%
DeltaZ *= %JoyMultiplier%
SetMouseDelay, -1 ; Makes movement smoother.
MouseMove, %DeltaR%, %DeltaZ%, 0, R
}
return
MouseWheel:
GetKeyState, JoyPOV, %JoyNum%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