AutoHotkey Community

It is currently May 26th, 2012, 7:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: May 19th, 2008, 3:20 am 
I intend to use one axis for number 1 to 9 , but I don't kown how to deal with the left and up direction ,the code is simple,any suggestion?
Thanks~
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 = numpad6
else if JoyX < 30
    KeyToHoldDown = numpad4
else if JoyY > 70
    KeyToHoldDown = numpad2
else if JoyY < 30
    KeyToHoldDown = numpad8

; here want to send numpad7 numpad9 numpad1 numpad3
;need help
;  JoyX > 70 and JoyY < 30 KeyToHoldDown = numpad9
;  JoyX > 70 and JoyY > 70 KeyToHoldDown = numpad3
;  JoyX < 30 and JoyY < 30 KeyToHoldDown = numpad7
;  JoyX < 30 and JoyY > 70 KeyToHoldDown = numpad1

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

joy11::
Send 5
return

[Moderator's note: Added "joystick" to the thread title.]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 8:34 am 
As you've choosen number as your (Guest)nick, I thought about how I should provide you one axis! Guess it might make sense to add the keyword 'joystick' somewhere at the subject line to attract the relevant type of people for your topic (a moderator can do this for you).
Anyway. Good luck. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 9:26 am 
BoBo² wrote:
As you've choosen number as your (Guest)nick, I thought about how I should provide you one axis! Guess it might make sense to add the keyword 'joystick' somewhere at the subject line to attract the relevant type of people for your topic (a moderator can do this for you).
Anyway. Good luck. 8)


Thanks for the advice, :)
The axis direction is not easy control, I add this ,but it doesn't work.

Code:
if JoyX > 70 and JoyY < 30
    KeyToHoldDown = numpad9
else if JoyX > 70 and JoyY > 70
     KeyToHoldDown = numpad3
else if JoyX < 30 JoyY < 30
     KeyToHoldDown = numpad7
else if JoyX < 30 JoyY > 70
     KeyToHoldDown = numpad1

else if JoyX > 70
    KeyToHoldDown = numpad6


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 10:41 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
The code in red is interpreted as literal text:
Code:
if JoyX > 70 and JoyY < 30
The equivalent expression is:
Code:
if (JoyX > "70 and JoyY < 30")
What you probably want is:
Code:
if (JoyX > 70 and JoyY < 30)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 2:12 pm 
Lexikos wrote:
The code in red is interpreted as literal text:
Code:
if JoyX > 70 and JoyY < 30
The equivalent expression is:
Code:
if (JoyX > "70 and JoyY < 30")
What you probably want is:
Code:
if (JoyX > 70 and JoyY < 30)


Thanks very much,Lexikos :D
I changed the code ,and it works someway,though its behave is not easy
to control, when I push the left up direction,sometimes it send 7,sometimes 47 ,sometimes 478, the left,up,down,right direction works very well,may be I should use two axises, left axis for 4 8 6 2,right axis for 1 7 9 3.


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 and JoyY < 30)
    KeyToHoldDown = numpad9
else if (JoyX > 70 and JoyY > 70)
     KeyToHoldDown = numpad3
else if (JoyX < 30 and JoyY < 30)
     KeyToHoldDown = numpad7
else if (JoyX < 30 and JoyY > 70)
     KeyToHoldDown = numpad1

else if JoyX > 70
    KeyToHoldDown = numpad6
else if JoyX < 30
    KeyToHoldDown = numpad4
else if JoyY > 70
    KeyToHoldDown = numpad2
else if JoyY < 30
    KeyToHoldDown = numpad8
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

joy11::
send 5
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 8:28 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
you can modify this script:
Code:
; [VxE]'s joyaxi to numpad [1~9] scriptlet
*Joy1::SetTimer, jtnWatchAxis, 5
jtnWatchAxis:
SetKeyDelay, -1
SetFormat, Float, 0.0
GetKeyState, jx, JoyX, P
GetKeyState, jy, JoyY, P
PreviousKeyHeld := KeyToHoldDown
;;;;; Since a joyaxis ranges from 0 to 100 with 50 being in the middle,
;;;;; we'll map the ranges 0~33, 34~67, 68~100, to 0, 1, 2, respectively
KeyToHoldDown := "NumPad" . (((jx + 1) // 34) + 7 - 3 * ((jy + 1) // 34))
If PreviousKeyHeld != %KeyToHoldDown%
{
   If PreviousKeyHeld
      Send {blind}{%PreviousKeyHeld% Up}
   Send {blind}{%KeyToHoldDown% Down}
}
If !GetKeyState("Joy1", "p")
{
   SetTimer, jtnWatchAxis, off
   Send {blind}{%KeyToHoldDown% Up}
   KeyToHoldDown =
}
return

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2008, 7:50 am 
[VxE] wrote:
you can modify this script:
Code:
; [VxE]'s joyaxi to numpad [1~9] scriptlet
*Joy1::SetTimer, jtnWatchAxis, 5
jtnWatchAxis:
SetKeyDelay, -1
SetFormat, Float, 0.0
GetKeyState, jx, JoyX, P
GetKeyState, jy, JoyY, P
PreviousKeyHeld := KeyToHoldDown
;;;;; Since a joyaxis ranges from 0 to 100 with 50 being in the middle,
;;;;; we'll map the ranges 0~33, 34~67, 68~100, to 0, 1, 2, respectively
KeyToHoldDown := "NumPad" . (((jx + 1) // 34) + 7 - 3 * ((jy + 1) // 34))
If PreviousKeyHeld != %KeyToHoldDown%
{
   If PreviousKeyHeld
      Send {blind}{%PreviousKeyHeld% Up}
   Send {blind}{%KeyToHoldDown% Down}
}
If !GetKeyState("Joy1", "p")
{
   SetTimer, jtnWatchAxis, off
   Send {blind}{%KeyToHoldDown% Up}
   KeyToHoldDown =
}
return


Thanks a lot,[VxE],you are great, I also find something useful for me in your home thread , I will try your script. :)


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, kkkddd1, Tipsy3000, Yahoo [Bot] and 64 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