AutoHotkey Community

It is currently May 27th, 2012, 10:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: keyboard to joystick
PostPosted: December 22nd, 2004, 12:50 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
I asked earlier about how to do the joystick respond with certain keyboard keys, and specially make the POV act like the arrow keys in the keyboard.

Can you pleas give me an example script?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2004, 1:22 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It would be nice to know if this works since I don't have a POV control here to test with:
Code:
#Persistent
SetTimer, WatchPOV, 5
return

WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
if POV < 0   ; No angle to report
   KeyToHoldDown =
else if POV > 31500                 ; 315 to 360 degrees: Forward
   KeyToHoldDown = Up
else if POV between 0 and 4500      ; 0 to 45 degrees: Forward
   KeyToHoldDown = Up
else if POV between 4501 and 13500  ; 45 to 135 degrees: Right
   KeyToHoldDown = Right
else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
   KeyToHoldDown = Down
else                                ; 225 to 315 degrees: Left
   KeyToHoldDown = Left

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down
   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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2004, 1:30 pm 
Quote:
Can you pleas give me an example script?

I guess that's the killer phrase !?

Can you give us some code you've created we can play with ?
What have you taken from AHK's help so far ?

If none of the above, are you willing to pay for it ?
Or d'ya wanna live your life, while I'm sitting there dealin with an issue which I wouldn't deal with if I've had ignored your post ??? :roll:

POV ? TBH. I've no idea what's that?
PluralisticOrkVomit ???


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2004, 2:44 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I posted the example above after realizing that even after reading the Tutorial, it's not something someone without programming or scripting experience could be expected to easily produce.

Also, this seems like it would be something commonly wanted by joystick users. If so, it's good to have it posted here for future use.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2004, 9:41 am 
hi, i would also want to know how to use this script, im new to this, so do i just run this script and assign keyboard to joy pad?
i also tried out the joystickmoush.ahk program and i like it very much for playing games with the pad for mouse,
so i wanted to know how to add mouse and keyboards movements to the joy pad which consists of 8 buttons,
would be nice to play games with a joy pad instead of mouse and keyboard.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2004, 5:47 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
logan wrote:
how to add mouse and keyboards movements to the joy pad which consists of 8 buttons, would be nice to play games with a joy pad instead of mouse and keyboard.
If the 8 buttons are seen as joystick buttons by the joystick test script, you can remap them to become keyboard keys for gaming as shown in the following example:

Joy1::
Send, {Up down} ; Hold down the up-arrow key.
KeyWait, Joy1 ; Wait for the joystick button to be released
Send, {Up up} ; Release hte up-arrow key.
return

If you frequently hold down more than one button simultaneously, the above might have to be rewritten to use timers, similar to how the Joystick-as-Mouse script operates.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2004, 12:32 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
Chris, I apreciate your effort.

Hey Bobo, if want to ignore my request you may do it also, not that I pointed with a gun at you and said "if you don't give me the sample script I'll burn you houses!"

I passed about 4 hours of my precious time figuring out how the scripted worked, and never saw a significant example as to how the POV was actually made a possible key to change.

I'll check and see if it works.

Thanks again


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2004, 1:01 pm 
It worked well, at least for the four main directions, it lacks of diagonal input, I tried to ad the & to make the script press the up and left key for when KeyToHoldDown is 31500, for example, but it didn't work.
Another probable solution could have been make the up and left key equal the up-left number (31500). I've tried every way I could had immagined but couldn't achieve anything.


else if POV 31500
KeyToHoldDown = Up&left

didn't work though.

Any tips?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2004, 1:32 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
The below uses the same approach except it extends it to two keys to support eight directions:
Code:
#Persistent
SetTimer, WatchPOV, 5
return

WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
Key1ToHoldDownPrev = %Key1ToHoldDown%
Key2ToHoldDownPrev = %Key2ToHoldDown%
; Each "Prev" variable now holds the key that was down before (if any).

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, check for ranges:
if POV < 0   ; No angle to report
{
   Key1ToHoldDown =
   Key2ToHoldDown =
}
else if POV > 33750                 ; 337.5 to 360 degrees: Forward
{
   Key1ToHoldDown = Up
   Key2ToHoldDown =
}
else if POV between 0 and 2250      ; 0 to 22.5 degrees: Forward
{
   Key1ToHoldDown = Up
   Key2ToHoldDown =
}
else if POV between 2251 and 6750   ; Up+Right
{
   Key1ToHoldDown = Up
   Key2ToHoldDown = Right
}
else if POV between 6751 and 11250  ; Right
{
   Key1ToHoldDown =
   Key2ToHoldDown = Right
}
else if POV between 11251 and 15750 ; Down+Right
{
   Key1ToHoldDown = Down
   Key2ToHoldDown = Right
}
else if POV between 15751 and 20250 ; Down
{
   Key1ToHoldDown = Down
   Key2ToHoldDown =
}
else if POV between 20251 and 24750 ; Down+Left
{
   Key1ToHoldDown = Down
   Key2ToHoldDown = Left
}
else if POV between 24751 and 29250 ; Left
{
   Key1ToHoldDown =
   Key2ToHoldDown = Left
}
else if POV between 29251 and 33750 ; Up+Left
{
   Key1ToHoldDown = Up
   Key2ToHoldDown = Left
}

SetKeyDelay -1  ; Avoid delays between keystrokes.

if Key1ToHoldDown <> %Key1ToHoldDownPrev%  ; Key #1 needs adjusting.
{
   if Key1ToHoldDownPrev <>   ; There is a previous key to release.
      Send, {%Key1ToHoldDownPrev% up}  ; Release it.
   if Key1ToHoldDown <>   ; There is a key to press down.
      Send, {%Key1ToHoldDown% down}  ; Press it down.
}
if Key2ToHoldDown <> %Key2ToHoldDownPrev%  ; Key #2 needs adjusting.
{
   if Key2ToHoldDownPrev <>   ; There is a previous key to release.
      Send, {%Key2ToHoldDownPrev% up}  ; Release it.
   if Key2ToHoldDown <>   ; There is a key to press down.
      Send, {%Key2ToHoldDown% down}  ; Press it down.
}
return

Edit: Fixed bug.


Last edited by Chris on January 10th, 2005, 5:20 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2004, 12:22 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: great, but the loop...
PostPosted: January 4th, 2005, 1:07 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
Diagonals now work but strangely it follows some kind of up and down loop that keeps the directions from being pressed and holded down, instead a turbo-like message is sent. The problem is, I don't understand why is this so. Any suggestions?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2005, 9:23 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I'll need some clarification on exactly what it does. Perhaps someone else with a POV joystick can try out the above to shed more light on this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: more clearly
PostPosted: January 8th, 2005, 10:52 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
I guess I wasn't clear. What happens with the joypad is a turbo-like effect; that is, if I press up, instead of being pressed while held down as supposedly, it reapetedly presses and realeses the arrow key up. Same thing happens to all directions.

Strange as it may seem this is what happens.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2005, 12:20 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for clarifying. Does the original 4-direction script do the same thing? If so, that probably means the joystick reports an unexpected POV number sometimes.

Since I don't have a POV joystick to test this with, you'll probably have to debug it yourself unless someone else steps in. You could try using the joystick test script to see what values your joystick is actually reporting, and compare them against what the script assumes they should be.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2005, 3:47 pm 
Offline

Joined: December 17th, 2004, 6:52 pm
Posts: 7
Location: Rome, Italy
The four directional script worked without the turbo-like effect.

I think it could be what you are saying, instead of specifying the range of values from the POV's direction, I'll try and specify the excat diagonal value (4500 = up-right, 13500 = down-right, 22500, 31500 = up-left.)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Edd, Exabot [Bot], HotkeyStick, Yahoo [Bot] and 14 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