 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Sun Feb 07, 2010 12:29 pm Post subject: Another Joystick to keyboard mapper with some more functions |
|
|
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.
Last edited by fragman on Thu Feb 25, 2010 10:17 pm; edited 1 time in total |
|
| Back to top |
|
 |
Binko Guest
|
Posted: Sun Feb 07, 2010 2:24 pm Post subject: |
|
|
WoW Ty dude! You make my day with that script! I was looking for smthing like that for games espesally AION now
HF |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Sun Feb 07, 2010 2:28 pm Post subject: |
|
|
I'm probably going to add some fullscreen detection to exclude games, but you can use this version or disable it then.
I will probably "re-include" a few apps like media players, fullscreen browsers,... , so that hotkeys etc work there. |
|
| Back to top |
|
 |
The Naked General
Joined: 22 Feb 2009 Posts: 21 Location: Dallas TX
|
Posted: Sun Feb 07, 2010 9:01 pm Post subject: |
|
|
Very nice script fragman, the abs axis evaluator makes it very clean. I was wondering since you use an xbox controller on win7 if you have seen any Xinput drivers for it. I wrote a scipt simmilar to this for XP but it was reliant on wrapping Xinput funtions to split the Z axis or triggers becuase they read as one axis with %50 at idle. So I had to rewrite it using postmessage to play WoW with it. Just wanted to add a sugestion that I use in my script, I use a seperate timer to evaluate the Z axis, and then use the result in other send parts of it to use the triggers as a kind of shift key. Just gives you allot more options if you start running out of buttons. Anyway, great script, thanks allot.  _________________ "lol, i made this thing, but it didn't work... so I read the forums and now it does!" |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Sun Feb 07, 2010 9:08 pm Post subject: |
|
|
I haven't yet needed modifier keys, but I'll consider them when I require more keys. I consider this script mainly for remote controlling windows, not for use in games, but it may be adjusted as needed of course.
I couldn't get the XBCD driver working with my controller sadly, I would've liked to use the extended functionality. |
|
| Back to top |
|
 |
duveit
Joined: 08 Dec 2009 Posts: 9
|
Posted: Sun Feb 21, 2010 11:36 am Post subject: |
|
|
seems great so far, although i cant use shift on my keyboard now for some reason. anyhow, exactly what i looked for.  |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Sun Feb 21, 2010 12:10 pm Post subject: |
|
|
Are you sure this is related to this script?
I'm not doing anything with the shift key.
Also, is there a proper way to detect if the joystick/gamepad is connected?
I need this disabled if there is none. |
|
| Back to top |
|
 |
duveit
Joined: 08 Dec 2009 Posts: 9
|
Posted: Thu Feb 25, 2010 12:47 pm Post subject: |
|
|
| fragman wrote: | Are you sure this is related to this script?
I'm not doing anything with the shift key.
Also, is there a proper way to detect if the joystick/gamepad is connected?
I need this disabled if there is none. |
Might be someting else, I have two othe autohotkey scripts running at the same time, however I've never experienced this side effect before. Maybe its a combination. And.., I dont know about checking if its avail. |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Thu Feb 25, 2010 10:19 pm Post subject: |
|
|
| I have updated the script so it doesn't screw up mouse movement when no joystick is connected. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|