Solved

AutoHotKey programming a Joystick

Posted on 2014-11-15
2
263 Views
Last Modified: 2014-11-15
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.
0
Comment
Question by:Tim Phillips
2 Comments
 
LVL 18

Accepted Solution

by:
Peter Hutchison earned 500 total points
Comment Utility
Would you could do is queue the buttons and save (push) them in an array. The the code would 'pop' entries from the queue and deal with them in order and thus enable to catch most of the commands. If not then a better joystick is required.
0
 
LVL 6

Author Comment

by:Tim Phillips
Comment Utility
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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now