Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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.


share|improve this question

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .