Useful; good work.
Are you using the unofficial Xbox Controller Drivers (XBCD)? Have you noticed the button mappings can be completely changed via the XBCD Setup util?
I use 360 version of XBCD with my wired Xbox 360 pad, since they're MUCH more powerful than the official drivers. (I don't think there are official drivers for the original Xbox pads.) The Xbox 360 uses standard USB, so I'd guess 360 pads would be more commonly used on PCs than the original pads. There's also a "Windows" version of the 360 pad, but the only difference is they package it with a copy of the official drivers.
Here's what I'm using atm, built on top of your script:
Code:
#Persistent
; 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
JoyThreshold = 3
; Change the following to true to invert the Y-axis, which causes the mouse to
InvertYAxis := false
JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold
if InvertYAxis
YAxisMultiplier = -1
else
YAxisMultiplier = 1
SetTimer, TriggerCheck, 5
SetTimer, POVCheck, 5
SetTimer, WatchJoystick, 10
;SetTimer, HelpBox, 5
LastWheelTick := A_TickCount ; for wheel timer -- Lexikos
WheelUpTime := WheelDownTime := 0
; Button and Axis mappings -- Lexikos
BtnA = Joy1
BtnB = Joy2
BtnX = Joy3
BtnY = Joy4
BtnWhite = Joy5 ; 360: right bumper
BtnBlack = Joy6 ; 360: left bumper
BtnLT = Joy7
BtnRT = Joy8
BtnLS = Joy9
BtnRS = Joy10
BtnBack = Joy11
BtnStart = Joy12
AxisLX = JoyX
AxisLY = JoyY
AxisRX = JoyU
AxisRY = JoyR
Btns = A,B,X,Y,White,Black,LT,RT,LS,RS,Back,Start
Loop, Parse, Btns, `,
if IsLabel("Pressed" A_LoopField)
Hotkey, % Btn%A_LoopField%, Pressed%A_LoopField%
return
/*
HelpBox:
If LTrig=D
{
MouseGetPos, MX, MY
Gui, +Resize
Gui, Add, Pic, xm vPic
GuiControl,, Pic, *w400 *h362 xbox LEFT.jpg ; Load the image.
Gui, Show, x%MX% y%MY% AutoSize, xbox LEFT.jpg ; Resize the window to match the picture size.
return
}
If RTrig=D
{
MouseGetPos, MX, MY
Gui, +Resize
Gui, Add, Pic, xm vPic
GuiControl,, Pic, *w400 *h362 xbox RIGHT.jpg ; Load the image.
Gui, Show, x%MX% y%MY% AutoSize, xbox RIGHT.jpg ; Resize the window to match the picture size.
return
}
If LTrig=U
Gui, Destroy
If RTrig=U
Gui, Destroy
return
else
{
MouseGetPos, MX, MY
Gui, +Resize
Gui, Add, Pic, xm vPic
GuiControl,, Pic, *w400 *h362 xbox BOT.jpg ; Load the image.
Gui, Show, x%MX% y%MY% AutoSize, xbox RIGHT.jpg ; Resize the window to match the picture size.
return
}
If LDown=0
Gui, Destroy
If RDown=0
Gui, Destroy
return
*/
TriggerCheck:
GetKeyState, LTrig, %BtnLT%
GetKeyState, Rtrig, %BtnRT%
If LTrig=D
LDown=1
If LTrig=U
LDown=0
If RTrig=D
RDown=1
If RTrig=U
RDown=0
Both:=RDown+LDown
return
PressedWhite:
Button=1
If Both=2
{
Send {Blind}z
return
}
Send {Enter}
return
PressedLT:
Button=0
Keywait %BtnLT%
If Button=0
Send {Backspace}
return
PressedRT:
Button=0
Keywait %BtnRT%
If Button=0
Send {Space}
return
PressedBlack:
Button=1
If Both=2
{
Send {Blind}y
return
}
If LDown=1
{
Send {Blind}.
return
}
If RDown=1
{
Send {Blind}.
return
}
return
PressedA:
Button=1
If Both=2
{
Send {Blind}q
return
}
If LDown=1
{
Send {Blind}a
return
}
If RDown=1
{
Send {Blind}i
return
}
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, left,,, 1, 0, D ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 10
return
PressedB:
Button=1
If Both=2
{
Send {Blind}r
return
}
If LDown=1
{
Send {Blind}b
return
}
If RDown=1
{
Send {Blind}j
return
}
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, right,,, 1, 0, D ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 10
return
PressedX:
Button=1
If Both=2
{
Send {Blind}s
return
}
If LDown=1
{
Send {Blind}c
return
}
If RDown=1
{
Send {Blind}k
return
}
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, middle,,, 1, 0, D ; Hold down the right mouse button.
SetTimer, WaitForMiddleButtonUp, 10
return
WaitForLeftButtonUp:
GetKeyState, ButtA, %BtnA%
if ButtA=D
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:
GetKeyState, ButtB, %BtnB%
if ButtB=D
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:
GetKeyState, ButtX, %BtnX%
if ButtX=D
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
PressedY:
Button=1
If Both=2
{
Send {Blind}t
return
}
If LDown=1
Send {Blind}d
If RDown=1
Send {Blind}l
return
POVCheck:
GetKeyState, POV, JoyPOV
If (OLDPov=POV)
{
; Msgbox, %oldpov%=%pov%
return
}
OLDPov = %POV%
If POV=0
GOTO POVUp
else If POV=9000
GOTO POVRight
else If POV=27000
GOTO POVLeft
else If POV=18000
GOTO POVDown
return
POVDown:
Button=1
If Both=2
{
Send {Blind}u
return
}
If LDown=1
Send {Blind}e
If RDown=1
Send {Blind}m
return
POVRight:
Button=1
If Both=2
{
Send {Blind}v
return
}
If LDown=1
Send {Blind}f
If RDown=1
Send {Blind}n
return
POVLeft:
Button=1
If Both=2
{
Send {Blind}w
return
}
If LDown=1
Send {Blind}g
If RDown=1
Send {Blind}o
return
POVUp:
Button=1
If Both=2
{
Send {Blind}x
return
}
If LDown=1
Send {Blind}h
If RDown=1
Send {Blind}p
return
WatchJoystick:
MouseNeedsToBeMoved := false ; Set default.
SetFormat, float, 03
GetKeyState, joyx, %AxisLX%
GetKeyState, joyy, %AxisLY%
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 * YAxisMultiplier, 0, R
}
; Scroll wheel with Right stick (vertical axis) -- Lexikos
GetKeyState, joyy, %AxisRY%
if joyy > %JoyThresholdUpper%
{
WheelUpInterval := 10 + (1.0 - (joyy-JoyThresholdUpper)/(50-JoyThreshold)) * 500
WheelDownInterval := 0
}
else if joyy < %JoyThresholdLower%
{
WheelUpInterval := 0
WheelDownInterval := 10 + (1.0 - (JoyThresholdLower-joyy)/(50-JoyThreshold)) * 500
}
else
WheelDownInterval := 0, WheelUpInterval := 0
WheelTimeDelta := A_TickCount-LastWheelTick, LastWheelTick := A_TickCount
if (WheelUpInterval > 0)
{
WheelUpTime += WheelTimeDelta
Loop { ; loop so that WheelUpInterval can be shorter than the (actual) timer delay
if (WheelUpTime < WheelUpInterval)
break
WheelUpTime -= WheelUpInterval
Click WheelUp
}
}
if (WheelDownInterval > 0)
{
WheelDownTime += WheelTimeDelta
Loop {
if (WheelDownTime < WheelDownInterval)
break
WheelDownTime -= WheelDownInterval
Click WheelDown
}
}
return
What I added:
- The buttons and axes are mapped via the Btn/Axis variables. This allows the script to be used with practically any gamepad or joystick, as well as other xbox pads with different button mappings. The default mappings are what I use with my 360 pad, so you'll need to change them if you want to try this version of the script.
- Hotkeys are automatically registered for each button -> Pressed%button_name% label -- e.g. PressedA, PressedWhite.
- I added {Blind} to each Send {letter}. This allows CapsLock to work (though there is no button for CapsLock yet.)
- The right stick's vertical axis controls the mouse wheel.
I removed the CapsLockState subroutine, since the current state of caps lock can be determined with:
Code:
CapsLockOn := GetKeyState("CapsLock","T")
and CapsLock can be toggled via
Code:
Send {CapsLock}
(SetCapsLockState actually sends a CapsLock keypress.)
You may use my code additions (or not) however you see fit.
Quote:
Get the Rumble Feature working. Does anyone know how to activate the actuators in the XBOX Controller?
I believe that requires DirectInput (part of DirectX.) It should be possible in AutoHotkey with DllCall, but not easy, and afaik hasn't been done before.