Solved

AutoHotKey programming a Joystick

Posted on 2014-11-15
2
277 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 19

Accepted Solution

by:
Peter Hutchison earned 500 total points
ID: 40444314
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
ID: 40445334
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

733 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