AutoHotkey Community

It is currently May 27th, 2012, 4:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Stop autorepeating key
PostPosted: February 20th, 2010, 4:41 am 
Hello, can anyone help me on this, please.

The next example is a joystick sending to keys script. How can I stop the pressing key continuously and press just once.

Code:
#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return

WatchAxis:
GetKeyState, JoyX, JoyX  ; Get position of X axis.
GetKeyState, JoyY, JoyY  ; Get position of Y axis.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

if JoyX > 70
    KeyToHoldDown = Right
else if JoyX < 30
    KeyToHoldDown = Left
else if JoyY > 70
    KeyToHoldDown = Down
else if JoyY < 30
    KeyToHoldDown = Up
else
    KeyToHoldDown =

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return


Thanks.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 4:44 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
Which key?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 4:47 am 
If I move joystick right it presses right key till I leave the joystick. The thing I want to do is move the joystick right, send the key once. No repeat keys.

Let's say right joystick = "a" key (no repeat)

Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 4:51 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
Anonymous wrote:
If I move joystick right it presses right key till I leave the joystick. The thing I want to do is move the joystick right, send the key once. No repeat keys.

Let's say right joystick = "a" key (no repeat)

Thanks


Code:
; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return


Remove the 'up' and 'down' words. This should change it to a single send.

You may need to remove the 'up' line entirely and just change the down line to remove 'down'.

Is this for star trek online?

Also don't let the variable names 'keytoholddown' confuse you, it could just as easily be named 'key'.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Mickers, rbrtryn and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group