I'm still working on a larger tweaking/enhancement script for Win7, but I decided to release a small part of code I wrote up yesterday.
The idea is to use a gamepad (in my case, an xbox360 controller) as a remote control, for watching movies from your bed, checking a webpage, etc
Video watching is targeted at VLC, but it might work well with others too. You can play/pause with the start button, and adjust volume with the second analog stick.
I assigned mouse (cursor, buttons and wheel) to the gamepad, arrow keys, space, enter and alt+up (upwards in explorer) to buttons, also I added the zoom function so you can read text more easily from distance. I also applied some simple math for better cursor control.
Code:
sign(x)
{
if(x!=0)
return x/abs(x)
else
return 1
}
SetTimer, CheckJoystick, 5
SetTimer, Arrows, 70
;Run this function at startup if you include this file in other scripts
JoystickStart()
{
SetTimer, CheckJoystick, 5
SetTimer, Arrows, 70
}
CheckJoystick:
XAxis:=0
YAxis:=0
GetKeyState, XAxis, JoyX ;Get axis data
GetKeyState, YAxis, JoyY
GetKeyState, RAxis, JoyR
GetKeyState, UAxis, JoyU
if(RAxis<20) ;Mouse wheel
Send {WheelUp}
if(RAxis>80)
Send {WheelDown}
if(UAxis<20)
Send {WheelLeft}
if(UAxis>80)
Send {WheelRight}
if(XAxis||YAxis)
{
XAxis-=50 ;Mouse cursor
YAxis-=50
if(abs(XAxis)<10)
XAxis:=10*sign(XAxis)
if(abs(YAxis)<10)
YAxis:=10*sign(YAxis)
XAxis-=10*sign(XAxis)
YAxis-=10*sign(YAxis)
XAxis:=0.1*abs(Round(XAxis))**1.5*sign(XAxis)
YAxis:=0.1*abs(Round(YAxis))**1.5*sign(YAxis)
MouseMove, XAxis,YAxis,0,R
}
return
Arrows: ;Arrows have separate label because of timing
GetKeyState, POV, JoyPOV
if(POV>=0)
{
if(POV=0||POV=4500||POV=31500)
Send {Up}
if(POV=22500||POV=27000||POV=31500)
Send {Left}
if(POV=13500||POV=18000||POV=22500)
Send {Down}
if(POV=4500||POV=9000||POV=13500)
Send {Right}
}
return
Joy1::
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, left,,, 1, 0, D ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 10
return
Joy2::
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, right,,, 1, 0, D ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 10
return
Joy3::
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, middle,,, 1, 0, D ; Hold down the right mouse button.
SetTimer, WaitForMiddleButtonUp, 10
return
WaitForLeftButtonUp:
if GetKeyState("Joy1")
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("Joy2")
return ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, right,,, 1, 0, U ; Release the mouse button.
return
WaitForMiddleButtonUp:
if GetKeyState("Joy3")
return ; The button is still, down, so keep waiting.
; Otherwise, the button has been released.
SetTimer, WaitForMiddleButtonUp, off
SetMouseDelay, -1 ; Makes movement smoother.
MouseClick, middle,,, 1, 0, U ; Release the mouse button.
return
Joy4::Send {Return}
Joy5::Send #{NumpadSub}
Joy6::Send #{NumpadAdd}
Joy7::Send !{Up}
Joy8::Send {Space}
Feel free to tweak it to your needs, and let me know of possible improvements. I haven't found a use for the "trigger" axis buttons of the xbox controller yet, I could probably add the on-screen keyboard if you need to type something. Also the Mouse wheel left/right doesn't appear to work for me, maybe because my mouse doesn't have it? Just a wild guess, I'm running latest ahk_l.