Link to home
Start Free TrialLog in
Avatar of Tim Phillips
Tim PhillipsFlag for United States of America

asked on

AutoHotKey programming a Joystick

I'm working on a project that sends txt via serial to an Arduino.  The Arduino interprets the txt and parses it to get instructions for motors.  Problem is that repeating keystrokes aren't working right with my basic joystick (no potentiometers, just on/off buttons even in the stick).  Here is what I'm trying to send in English:  
If button 14 is pressed send, in txt, "joy14".  If button 13 is pressed send, in txt, "joy13".  If both button 13 and 14 are pressed send, in txt, "both".

I was finally able to code this, but I lost the repeating nature of the button.  I need the button/buttons to continuously send the keystrokes if held down.  Here is the code I have that DOES have diagonals:

Joy13::
SetTimer, WaitForJoy1, 500
return

WaitForJoy1:
if not GetKeyState("Joy14")
{
  Send joy13
  SetTimer, WaitForJoy1, off
  return
}

if GetKeyState("Joy14")
{
  Send both
  SetTimer, WaitForJoy1, off
  return
}


Joy14::
SetTimer, WaitForJoy2, 500
return

WaitForJoy2:
if not GetKeyState("Joy13")
{
  Send joy14
  SetTimer, WaitForJoy2, off
  return
}

if GetKeyState("Joy13")
{
  Send both
  SetTimer, WaitForJoy2, off
  return
}

Open in new window


I'm open to suggestions including other programs/languages if it makes my life easier.
ASKER CERTIFIED SOLUTION
Avatar of Peter Hutchison
Peter Hutchison
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tim Phillips

ASKER

I got it to work doing this:

Joy13::
SetTimer, WaitForJoy13, 500
return

WaitForJoy13:

if not GetKeyState("Joy13")
{
  Send off
  SetTimer, WaitForJoy13, off
  return
}
else if not GetKeyState("Joy14")
{
  Send joy13
  return
}
else if GetKeyState("Joy14")
{
  Send both
  ;SetTimer, WaitForJoy13, off
  return
}

Open in new window