Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My joystick/gamepad has the standard 10 buttons plus the X and Y axis buttons. The script below works, but not the way I want it:

Right::
GetKeyState, state, JoyX
If state > 75 ;JoyX is pressed to right
SendInput testmessage

What this script will do is print "testmessage" when I press the right arrow key on my keyboard while JoyX is > 75. What I want is that, when JoyX is > 75, it will SendInput "testmessage" without having to press the right arrow key on my keyboard.

I tried using JoyX as hotkey, or X100 Y050, but I get an error message: the current hotkey JoyX will not be active bec it is not in the keyboard layout.

Thanks!

share|improve this question
add comment

1 Answer

The joystick has a state that must be polled as it doesn't have a "button" event to respond to. The following used Remapping a Joystick to Keyboard or Mouse for inspiration, in particular the Making a Joystick Axis or POV Hat Send Keystrokes or Mouse Clicks section. It uses a timer to periodically poll the state of the joystick and sends the input when the state is >75.

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return

WatchAxis:
GetKeyState, state, JoyX
If state > 75 ;JoyX is pressed to right
    SendInput testmessage
return

To get it to work well for you, you'll need to play around with the timer's poll frequency (currently 5) and may need to implement the KeyToHoldDown style of state tracking, otherwise you might send the text repeatedly.

share|improve this answer
    
Please note that this is currently untested, but I might try it later with an Xbox controller and see how it works. –  yhw42 Aug 2 '11 at 13:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.