Solved

AutoHotKey programming a Joystick

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using a variable to name output in powershell script 2 37
Java Loop 6 59
"Black Box" Testing of Control System Software 2 49
Powershell  and PSExec = Password failure 5 21
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.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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