?
Solved

AutoHotKey programming a Joystick

Posted on 2014-11-15
2
Medium Priority
?
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Peter Hutchison earned 1500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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…
Starting up a Project
Suggested Courses

765 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