AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Key Mapping for Nyko - Airflo PC and Dual Analog Gamepads
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Talven81



Joined: 26 Jun 2004
Posts: 9

PostPosted: Sat Jun 26, 2004 9:14 am    Post subject: Key Mapping for Nyko - Airflo PC and Dual Analog Gamepads Reply with quote

Well my script is completed enough for a release, please give feedback and let me know what you think.

This script is designed for the Nyko - Airflo PC but should be customizable for any Dual Analog Gamepad.

Code:

Avaliable Below


Last edited by Talven81 on Sat Jun 26, 2004 11:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sat Jun 26, 2004 12:08 pm    Post subject: Reply with quote

That's a very elaborate script, nice work.

I guess your controller is seen as only one joystick after all. I thought it might be seen as two, but if I'm reading the script right, they map the other stick onto some of the other remaining axes.

You might already know that things like the below can be simplified as "Send, m". In addition to performing a little better, there will be less delay because KeyDelay will be done only once:
Send, {m down}
Send, {m up}

If the speed at which keys are pushed down and released is important, this line near the top of the script will make things faster, though it might be too fast for the game to work reliably (especially if you use -1 vs. 0): SetKeyDelay, 0

If you want to make the script easier to reconfigure for a joystick other than the first, there is now a way to do that (I've been meaning to change the posted joystick script to do this too):

In the config section (to make it easier to configure):
joy1_key = z

In the auto-execute section:
Hotkey, %JoystickNumber%joy1, joy1

In the button section: you could replace the double colon with a single colon and make these other changes:
Joy1: ;Joystick Button 1
Send, {%joy1_key% down} ; Push and hold key
...
Send, {%joy1_key% up} ; Release key

Finally, because all variables are global, any time you have something like this:
GetKeyState, state, joy2
it's best to replace state with a unique variable name (e.g. state2). This avoids conflict/interference if you ever press down more than one button at a time.
Back to top
View user's profile Send private message Send e-mail
Talven81



Joined: 26 Jun 2004
Posts: 9

PostPosted: Sat Jun 26, 2004 6:04 pm    Post subject: Reply with quote

Chris wrote:

You might already know that things like the below can be simplified as "Send, m". In addition to performing a little better, there will be less delay because KeyDelay will be done only once:
Send, {m down}
Send, {m up}

If the speed at which keys are pushed down and released is important, this line near the top of the script will make things faster, though it might be too fast for the game to work reliably (especially if you use -1 vs. 0): SetKeyDelay, 0


That will help on some buttons, thank you. Right now this is the "functional" version (and if you notice v0.34 alpha LOL) and I'm working on delay checks, refining the script for minimal CPU usage, etc...

Quote:

If you want to make the script easier to reconfigure for a joystick other than the first, there is now a way to do that (I've been meaning to change the posted joystick script to do this too):


I also have a Microsoft Sidewinder Freestyle Pro (another gamepad) which is set up for tilt control, IE you tilt the entire controller left to go left, down to go forward... just like a plane. While I haven't found any games that DONT work with it, it would be nice to avoid having to config my controller for every game, so I may be testing this script out on that controller too once I am done.... oh and I have a Thrustmaster joystick too I can play with : )

Quote:
In the config section (to make it easier to configure):
joy1_key = z

In the auto-execute section:
Hotkey, %JoystickNumber%joy1, joy1

In the button section: you could replace the double colon with a single colon and make these other changes:
Joy1: ;Joystick Button 1
Send, {%joy1_key% down} ; Push and hold key
...
Send, {%joy1_key% up} ; Release key

Finally, because all variables are global, any time you have something like this:
GetKeyState, state, joy2
it's best to replace state with a unique variable name (e.g. state2). This avoids conflict/interference if you ever press down more than one button at a time.


Hahah I completely missed those GetKeyState command with the state variable, LOL... course I was working on this script until early morning so I wouldn't be supprised to see a few things like that haha.

Yeah since I am releasing this script to the public I plan to make it much easier to configure, and what I had in mind looks much like what you suggested, thank you again Smile
Back to top
View user's profile Send private message
Talven81



Joined: 26 Jun 2004
Posts: 9

PostPosted: Sat Jun 26, 2004 11:42 pm    Post subject: Reply with quote

New version, here it is... still working on it but major bugs are gone.

Code:
; PC Keyboard / Mouse Bindings Script for Nyko - Airflow PC, and Dual Analog Controllers
;
; Version 0.4 Alpha - General Gaming Layout
;
; Since Nyko has no software avaliable to customize their controller I decided to
; create one of my own.
;
; Made Posssible by www.autohotkey.com
;
; This script converts the Nyko Airflow PC controller into a functional controller for
; most games. It is based off the mouse script located on authotkey's website. Although
; this script is specifically desgined for the Nyko - Airflo PC it may be used with any
; dual analog gamepad.
;
; -- Features --
; (All # are imprinted on joystick buttons)
; These are my personal settings based off the Rainbow 6 layout (I use it
; on all my games) it may be screwy to you so modify the settings to your preference.
;
;   Airflo PC            Keyboard   Gaming Standard
;
;    Right Analog Joystick   Mapped to   Mouse      Mouse Look
;    Left Analog Joystick   Mapped to   WASD      Standard Run/Strafe
;    Button 1       Mapped to   Z      Reload
;    Button 2       Mapped to   Space      Use
;    Button 3       Mapped to   F      Rate of Fire
;    Button 4       Mapped to   X      Lay Down
;    Trigger 5       Mapped to    Left Shift   Duck
;    Trigger 6       Mapped to    Middle Mouse   Jump
;    Trigger 7       Mapped to    Right Mouse   Alt Fire
;    Trigger 8       Mapped to    Left Mouse   Fire
;    Select 9       Mapped to   TAB      Show Scores
;    Select 10       Mapped to   V      Drop Weapon
;    Select 11       Mapped to   ESC      Menu
;    Left Analog Down 12    Mapped to   Q      Peek Left
;    Right Analog Down 13    Mapped to   E      Peek Right
;    Pad Up          Mapped to   N      Zoom Map
;    Pad Down       Mapped to   M      Map
;    Pad Left       Mapped to   WheelUp      Next Weapon
;    Pad Right       Mapped to   WheelDown    Previous Weapon
;
; Special Binds
;   CTRL F6         Mapped to         Decrease Sensitivity
;   CTRL F7         Mapped to         Increase Sensitivity
;   
; ---New in This Version---
; Left analog stick jitter corrected.
; Buttons 2 and 3 now work properly.
;
; ---Coming Soon---
; Easily customizable Keybinds


;
; ---STARTUP---
;

#SingleInstance
SetBatchLines, 10ms
SetKeyDelay, 0

;
; ---USER CONFIGURATION---
; ---USER CONFIGURATION---
; ---USER CONFIGURATION---
;

; ---Multiple Joystick Configuration---
; If you have more than one Joystick, Increase this value to use a joystick other
; than the first (in which case you'll also need to change the Joy1:: and Joy2::
; labels below)
JoystickNumber = 1

; ---Right Analog Stick Sensitivity---
; Mouse Sensitivity, increase for more sensitive.
JoyMultiplier = 0.30

; ---Right Analog Stick Float---
; Decrease this value to require less joystick displacement-from-center
; to start moving the mouse.  However, you may need to calibrate your
; joystick -- ensuring it's properly centered -- to avoid cursor drift.
; The Airflo PC is usually pretty tight unless heavily weared.
JoyThreshold = 1

; ---Joystick Center Point----
JoyThresholdUpper = 50
JoyThresholdUpper += %JoyThreshold%
JoyThresholdLower = 50
JoyThresholdLower -= %JoyThreshold%

; ---Mouse L/R Mapping---
; Change these values to use button numbers other than 1 & 2 for the left & right
; mouse buttons, respectively (in which case you'll also need to change the Joy8::
; and Joy7:: labels below, not recommended)
ButtonLeft = 8
ButtonRight = 7

; ---Joystick Key Mapping---
; Since this is a work in progress not all features are avaliable yet.
joy1bind = z
joy2bind = Space
joy3bind = f
joy4bind = x
joy5bind = lshift
; joy6bind = MOUSE MIDDLE CLICK (Requires Recoding or this Option is Not Currently Rebindable)
; joy7bind = MOUSE RIGHT CLICK (Requires Recoding or this Option is Not Currently Rebindable)
; joy8bind = MOUSE LEFT CLICK (Requires Recoding or this Option is Not Currently Rebindable)
joy9bind = Tab
joy10bind = v
joy11bind = Esc
joy12bind = q
joy13bind = e
lstickupbind = w
lstickdownbind = s
lstickleftbind = a
lstickrightbind = d
padupbind = l
paddownbind = m
; padleftbind = MOUSE WHEEL UP (Requires Recoding or this Option is Not Currently Rebindable)
; padrightbind = MOUSE WHEEL DOWN (Requires Recoding or this Option is Not Currently Rebindable)
;
; ---END USER CONFIGURATION---
; ---END USER CONFIGURATION---
; ---END USER CONFIGURATION---
;


;
; ---END STARTUP---
;

SetTimer, WatchJoystick, 10
return

;
; ---Sensitivity Controls---
;
^F6::
if JoyMultiplier > 0
{
   JoyMultiplier -= 0.005

}
return

^F7::
   JoyMultiplier += 0.005
return

;
; ---BEGIN BUTTON CUSTOMIZATION---
;

; Add a prefix to each of the below hotkeys to use a joystick other
; than the first.  For example: 2Joy1 is the second joystick's first
; mouse button.

Joy1:: ;Joystick Button 1
Send, {z down} ; Push and hold Z key
Loop
{
   Sleep, 10 ;Check Every 10 ms
   GetKeyState, joy1state, joy1 ; Is key up or down?
   if joy1state = U  ; The button has been released, so break out of the loop.
      break
}
Send, {z up} ; Release Z key
return

Joy2::
Send, {Space down}
Loop
{
   Sleep, 10
   GetKeyState, joy2state, joy2
   if joy2state = U 
      break
}
Send, {Space up}
return

Joy3::
Send, {f down}
Loop
{
   Sleep, 10
   GetKeyState, joy3state, joy3
   if joy3state = U 
      break
}
Send, {f up}
return


Joy4::
Send, {x down}
Loop
{
   Sleep, 10
   GetKeyState, joy4state, joy4
   if joy4state = U 
      break
}
Send, {x up}
return

Joy5::
Send, {shiftdown}
Loop
{
   Sleep, 10
   GetKeyState, joy5state, joy5
   if joy5state = U   
      break
}
Send, {shiftup}
return

Joy6::
MouseClick, Middle, , , 1, ,D
Loop
{
   Sleep, 10
   GetKeyState, joy6state, joy6
   if joy6state = U 
      break
}
MouseClick, Middle, , , , ,U
return

Joy7::
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, right, , , 1, 0, D  ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 10
return

Joy8::
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left, , , 1, 0, D  ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 10
return

joy9::
Send, {Tab down}
Loop
{
   Sleep, 10
   GetKeyState, joy9state, joy9
   if joy9state = U
      break
}
Send, {Tab up}
return

joy10::
Send, {v down}
Loop
{
   Sleep, 10
   GetKeyState, joy10state, joy10
   if joy10state = U
      break
}
Send, {v up}
return

joy11::
Send, {Esc down}
Loop
{
   Sleep, 10
   GetKeyState, joy11state, joy11
   if joy11state = U
      break
}
Send, {Esc up}
return

joy12::
Send, {q down}
Loop
{
   Sleep, 10
   GetKeyState, joy12state, joy12
   if joy12state = U
      break
}
Send, {q up}
return

joy13::
Send, {e down}
Loop
{
   Sleep, 10
   GetKeyState, joy13state, joy13
   if joy13state = U
      break
}
Send, {e up}
return

;
; ---CHECK BUTTON STATES---
;

WaitForLeftButtonUp:
GetKeyState, jstate1, %JoystickNumber%Joy%ButtonLeft%
if jstate1 = D  ; The button is still, down, so keep waiting.
   return
; Otherwise, the button has been released.
SetTimer, WaitForLeftButtonUp, off
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left, , , 1, 0, U  ; Release the mouse button.
return

WaitForRightButtonUp:
GetKeyState, jstate2, %JoystickNumber%Joy%ButtonRight%
if jstate2 = D
   return
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
MouseClick, right, , , 1, 0, U
return

;
; ---BEGIN JOYSTICK WATCH---
;

WatchJoystick:
MoveMouse? = n
MoveStick? = n
SetFormat, float, 03
GetKeyState, joyx, %JoystickNumber%joyx
GetKeyState, joyy, %JoystickNumber%joyy
GetKeyState, joyr, %JoystickNumber%joyr
GetKeyState, joyz, %JoystickNumber%joyz
GetKeyState, joypov, %JoystickNumber%joypov

;
; --- RIGHT ANALOG JOYSTICK CONTROL ----
;

if joyr > %JoyThresholdUpper%
{
   MoveMouse? = y
   DeltaR = %joyr%
   DeltaR -= %JoyThresholdUpper%
}
else if joyr < %JoyThresholdLower%
{
   MoveMouse? = y
   DeltaR = %joyr%
   DeltaR -= %JoyThresholdLower%
}
else
   DeltaR = 0
if joyz > %JoyThresholdUpper%
{
   MoveMouse? = y
   DeltaZ = %joyz%
   DeltaZ -= %JoyThresholdUpper%
}
else if joyz < %JoyThresholdLower%
{
   MoveMouse? = y
   DeltaZ = %joyz%
   DeltaZ -= %JoyThresholdLower%
}
else
   DeltaZ = 0
if MoveMouse? = y
{
   DeltaR *= %JoyMultiplier%
   DeltaZ *= %JoyMultiplier%
   SetMouseDelay, -1  ; Makes movement smoother.
   MouseMove, %DeltaR%, %DeltaZ%, 0, R
}

;
; --- LEFT ANALOG JOYSTICK CONTROL ---
;

if joyX > %JoyThresholdUpper%
{
   MoveStick? = y
   DeltaX = %joyX%
   DeltaX -= %JoyThresholdUpper%
}
else if joyX < %JoyThresholdLower%
{
   MoveStick? = y
   DeltaX = %joyX%
   DeltaX -= %JoyThresholdLower%
}
else
   DeltaX = 0

if joyY > %JoyThresholdUpper%
{
   MoveStick? = y
   DeltaY = %joyY%
   DeltaY -= %JoyThresholdUpper%
}
else if joyY < %JoyThresholdLower%
{
   MoveStick? = y
   DeltaY = %joyY%
   DeltaY -= %JoyThresholdLower%
}
else
   DeltaY = 0

if MoveStick? = y
{
   DeltaX *= %JoyMultiplier%
   DeltaY *= %JoyMultiplier%
   if DeltaX < 0
   {
      GetKeyState, astate, a
      if astate = U
      {
         Send, {a down}
      }
      GetKeyState, dstate, d
      if dstate = D
      {
         Send, {d up}
      }
   }
   else if DeltaX > 0
   {
      GetKeyState, dstate, d
      if dstate = U
      {
         Send, {d down}
      }
      GetKeyState, astate, a
      if astate = D
      {
         Send, {a up}
      }
   }

   if DeltaY < 0
   {
      GetKeyState, wstate, w
      if wstate = U
      {
         Send, {w down}
      }
      GetKeyState, sstate, s
      if sstate = D
      {
         Send, {s up}
      }
   }
   else if DeltaY > 0
   {
      GetKeyState, sstate, s
      if sstate = U
      {
         Send, {s down}
      }
      GetKeyState, wstate, w
      if wstate = D
      {
         Send, {w up}
      }
   }
}

if DeltaY = 0
{
   GetKeyState, wstate, w
   GetKeyState, sstate, s
   if wstate = D
   {
      Send, {w up}
   }
   if sstate = D
   {
      Send, {s up}
   }
}

if DeltaX = 0
{
   GetKeyState, astate, a
   GetKeyState, dstate, d
   if astate = D
   {
      Send, {a up}
   }
   else if dstate = D
   {
      Send, {d up}
   }
}
;
; ---CONFIGURE DIRECTIONAL PAD---
;

if joypov = 0
{
   Send, l
return
}

if joypov = 9000
{
   sleep, 500
   MouseClick, WheelDown, , , 1
return
}

if joypov = 18000
{
   Send, m

return
}


if joypov = 27000
{
   sleep, 500
   MouseClick, WheelUp, , , 1
return
}
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Jun 27, 2004 1:13 am    Post subject: Reply with quote

I notice that you assign values to variables such as joy2bind but you never actually use the variable anywhere. This is probably one of the pending changes.
Back to top
View user's profile Send private message Send e-mail
scaryfencer



Joined: 09 Aug 2004
Posts: 2

PostPosted: Tue Aug 10, 2004 4:24 am    Post subject: Scripting for Point of View Reply with quote

I have to say this script is GREAT, I learned tons just messing with it and configuring it on my NYKO. I was wondering if anyone could help me with a very basic script that deals with the NYKO. The program I am using doesnt recognize input from the d-pad, so I am trying to re-map it to the "W A S D" keys. I have gotten this far
Code:
SetKeyDelay, 0

JoystickNumber = 1

SetTimer, WatchJoystick, 0

WatchJoystick:

GetKeyState, joypov, %JoystickNumber%JoyPOV

if joypov = 0
Send, {w down}

if joypov = 9000
Send, {d down}

if joypov = 18000
Send, {s down}

if joypov = 27000
Send, {a down}
 

joy5:: send e
but there are two serious problems with it. One, I had to write a bogus auto hot key "joy5::send e" just to keep the script from exiting automatically. I tried the #Persistence command, but it didnt work. What command should I use to keep the program from exiting?

Secondly, this script works fine in Notepad when i tested it, but when I used it for the application (zsnes), the keys never "auto up" like they do when tested in Notepad. The application thinks I am never letting go of the d-pad. I tried the following
Code:
if joypov = 0
Send, {w down}
Loop
{
   Sleep, 10
   GetKeyState, joypov, joyPOV
   if joypov = -1  ; The button has been released, so break out of the loop.
      break
}
Send, {w up}
return
but this doesnt seem to work. Any ideas on what I am doing wrong? Thanks in advance!!!
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Tue Aug 10, 2004 9:34 pm    Post subject: Reply with quote

Quote:
I had to write a bogus auto hot key "joy5::send e" just to keep the script from exiting automatically. I tried the #Persistence command, but it didnt work. What command should I use to keep the program from exiting?

The directive is #persistent. I tested your script with that and it didn't exit. However, to get in the right habit, you should also have a Return at the end of every subroutine. In addition, you should probably have a Return in the spot indicated below, otherwise the execution will fall right through into the subroutine:

SetKeyDelay, 0
JoystickNumber = 1
SetTimer, WatchJoystick, 0
return ; HERE

WatchJoystick:
...

Quote:
this script works fine in Notepad when i tested it, but when I used it for the application (zsnes), the keys never "auto up" like they do when tested in Notepad. The application thinks I am never letting go of the d-pad.

If you don't need the key to be held down for use with the game, use something like "Send s" rather than "Send {s down}". If you do need the key to be held down during the entire time you're holding the POV axis in a certain direction, you'll need something more complex (simlar to the example you posted). If this is the case, post a few more details and we'll try to help.
Back to top
View user's profile Send private message Send e-mail
scaryfencer



Joined: 09 Aug 2004
Posts: 2

PostPosted: Wed Aug 11, 2004 7:20 am    Post subject: NYKO D-pad script Reply with quote

Well, you were correct about that #persistent, not sure why I was having problems with it before but it's workin like a charm now. I ended up fixing the problem a little differently than you suggested, perhaps you guys can figure out an easier way to do what I did. But, here is a script that will turn the NYKO Point of View hat into a traditional D-pad style controller. Just load this script and tell your program that the d-pad is: w=up, d=right, s=down, and a=left.
Code:
#persistent

SetKeyDelay, 0

JoystickNumber = 1

SetTimer, WatchJoystick, 0

return

WatchJoystick:

GetKeyState, joypov, %JoystickNumber%JoyPOV

if joypov = 0
Send, {w down}{a up}{d up}{s up}

if joypov = 4500
Send, {w down}{d down}{a up}{s up}

if joypov = 9000
Send, {d down}{w up}{s up}{a up}

if joypov = 13500
Send, {d down}{s down}{a up}{w up}

if joypov = 18000
Send, {s down}{a up}{d up}{w up}

if joypov = 22500
Send, {s down}{a down}{w up}{d up}

if joypov = 27000
Send, {a down}{w up}{s up}{d up}

if joypov = 31500
Send, {a down}{w down}{d up}{s up}

if joypov = -1
Send, {w up}{d up}{a up}{s up}


return


It's ugly, but it works! If you want to turn the d pad into 4 buttons (like the yellow c buttons on the N64 controller) delete the commands for the diagonals (ie 4500, 13500, 22500, and 31500). Thanks for the awesome program!!!!!
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Wed Aug 11, 2004 10:34 am    Post subject: Reply with quote

Very clever (and simple) solution!
Back to top
View user's profile Send private message Send e-mail
Raenydyne
Guest





PostPosted: Wed Aug 18, 2004 7:31 am    Post subject: XBox controller support Reply with quote

I am hoping to use this to get my XBox controller to work with more games (on PC via USB). It maps fine with Halo, NFS HP2, Simpsons Hit and Run, and some others I tested but I run into the right joystick not working and the right trigger sticking usually making cameras spin around constantly. This is very good work and at the least I will have my PC controller working but my ultimate goal is 100% XBox control support. I just can't "feel" games (or perform I guess) without it. I'm one of those that can do much better with it than keyboard/mouse in FPS (some argue that back and forth). The mouse mapping in AHK is the coolest I am very excited to try this now. I also want to have better mapping for N64 Emus, this may be the ticket.
Back to top
Guest






PostPosted: Tue Oct 19, 2004 12:17 am    Post subject: Reply with quote

I noticed that with some Dual Analog gamepads, when you hold down a button it is only registered once by some games where if you hold the button down it repeats a certain action. I changed the script so that the Send. {<key> down} is inside the loop rather than outside. I haven't discovered any bugs with doing it this way.
Back to top
brice2nice
Guest





PostPosted: Sat Feb 12, 2005 8:35 pm    Post subject: Reply with quote

I will try it thanks Wink
Back to top
Cleaner



Joined: 06 Oct 2004
Posts: 4

PostPosted: Wed Apr 06, 2005 2:02 pm    Post subject: Reply with quote

Ok, I am getting much closer. Thanks for your help.

I decided to scrap what I had and so I went back to the scripts above. I combined the mouse script and the POV script above but switched the right and left analog control scripts (so the left analog is the mouse and right is the arrow keys). The POV is wasd keys.

Now everything is working great except for one thing. The right control stick wont do anything in the game. Outside the game it works just fine. I think the issue is that the buttons need to be held down longer inorder to register. I had a similar issue with the joy buttons and solved that with a KeyWait command

Code:

;button 1 to F1
   *Joy1::
   Send, {F1 down}
   KeyWait, Joy1
   Send, {F1 up}


Here is what I have been trying:
1- if I leave the script as it was (without returns) it would move but not stop moving.
2- if I add returns nothing happens
3- if I add down then up actions, it works but it works very choppy. ie: {left down}{left up}

What I think I need to do is have some kind of GetKeyState or KeyWait so I can check if the stick is changed or something. I am completely lost as to how to do that with a controller. I read through the online help and other scripts but I am still kinda lost as to how this would work. With joy buttons there is no problem.

I included the whole script just in case but seperated the area that I am having the issue with in the code below. The middle section is the section in question but remember all three sections make up one script.

Code:

; PC Keyboard / Mouse Bindings Script for Nyko - Airflow PC, and Dual Analog Controllers
;
; Version 0.4 Alpha - General Gaming Layout
;
; Since Nyko has no software avaliable to customize their controller I decided to
; create one of my own.
;
; Made Posssible by www.autohotkey.com
;
; This script converts the Nyko Airflow PC controller into a functional controller for
; most games. It is based off the mouse script located on authotkey's website. Although
; this script is specifically desgined for the Nyko - Airflo PC it may be used with any
; dual analog gamepad.
;
; -- Features --
; (All # are imprinted on joystick buttons)
; These are my personal settings based off the Rainbow 6 layout (I use it
; on all my games) it may be screwy to you so modify the settings to your preference.
;
;   Airflo PC            Keyboard   Gaming Standard
;
;    Right Analog Joystick   Mapped to   Mouse      Mouse Look
;    Left Analog Joystick   Mapped to   WASD      Standard Run/Strafe
;    Button 1       Mapped to   Z      Reload
;    Button 2       Mapped to   Space      Use
;    Button 3       Mapped to   F      Rate of Fire
;    Button 4       Mapped to   X      Lay Down
;    Trigger 5       Mapped to    Left Shift   Duck
;    Trigger 6       Mapped to    Middle Mouse   Jump
;    Trigger 7       Mapped to    Right Mouse   Alt Fire
;    Trigger 8       Mapped to    Left Mouse   Fire
;    Select 9       Mapped to   TAB      Show Scores
;    Select 10       Mapped to   V      Drop Weapon
;    Select 11       Mapped to   ESC      Menu
;    Left Analog Down 12    Mapped to   Q      Peek Left
;    Right Analog Down 13    Mapped to   E      Peek Right
;    Pad Up          Mapped to   N      Zoom Map
;    Pad Down       Mapped to   M      Map
;    Pad Left       Mapped to   WheelUp      Next Weapon
;    Pad Right       Mapped to   WheelDown    Previous Weapon
;
; Special Binds
;   CTRL F6         Mapped to         Decrease Sensitivity
;   CTRL F7         Mapped to         Increase Sensitivity
;   
; ---New in This Version---
; Left analog stick jitter corrected.
; Buttons 2 and 3 now work properly.
;
; ---Coming Soon---
; Easily customizable Keybinds


;
; ---STARTUP---
;

#SingleInstance
SetBatchLines, 10ms
SetKeyDelay, 0

;
; ---USER CONFIGURATION---
; ---USER CONFIGURATION---
; ---USER CONFIGURATION---
;

; ---Multiple Joystick Configuration---
; If you have more than one Joystick, Increase this value to use a joystick other
; than the first (in which case you'll also need to change the Joy1:: and Joy2::
; labels below)
JoystickNumber = 1

; ---Left Analog Stick Sensitivity---
; Mouse Sensitivity, increase for more sensitive.
JoyMultiplier = 0.30

; ---Left Analog Stick Float---
; Decrease this value to require less joystick displacement-from-center
; to start moving the mouse.  However, you may need to calibrate your
; joystick -- ensuring it's properly centered -- to avoid cursor drift.
; The Airflo PC is usually pretty tight unless heavily weared.
JoyThreshold = 1

; ---Joystick Center Point----
JoyThresholdUpper = 50
JoyThresholdUpper += %JoyThreshold%
JoyThresholdLower = 50
JoyThresholdLower -= %JoyThreshold%

; ---Mouse L/R Mapping---
; Change these values to use button numbers other than 1 & 2 for the left & right
; mouse buttons, respectively (in which case you'll also need to change the Joy8::
; and Joy7:: labels below, not recommended)
ButtonLeft = 8
ButtonRight = 7

; ---Joystick Key Mapping---
; Since this is a work in progress not all features are avaliable yet.
joy1bind = z
joy2bind = Space
joy3bind = f
joy4bind = x
joy5bind = lshift
; joy6bind = MOUSE MIDDLE CLICK (Requires Recoding or this Option is Not Currently Rebindable)
; joy7bind = MOUSE RIGHT CLICK (Requires Recoding or this Option is Not Currently Rebindable)
; joy8bind = MOUSE LEFT CLICK (Requires Recoding or this Option is Not Currently Rebindable)
joy9bind = Tab
joy10bind = v
joy11bind = Esc
joy12bind = q
joy13bind = e
lstickupbind = w
lstickdownbind = s
lstickleftbind = a
lstickrightbind = d
padupbind = l
paddownbind = m
; padleftbind = MOUSE WHEEL UP (Requires Recoding or this Option is Not Currently Rebindable)
; padrightbind = MOUSE WHEEL DOWN (Requires Recoding or this Option is Not Currently Rebindable)
;
; ---END USER CONFIGURATION---
; ---END USER CONFIGURATION---
; ---END USER CONFIGURATION---
;


;
; ---END STARTUP---
;

SetTimer, WatchJoystick, 10
return

;
; ---Sensitivity Controls---
;
^F6::
if JoyMultiplier > 0
{
   JoyMultiplier -= 0.005

}
return

^F7::
   JoyMultiplier += 0.005
return

;
; ---BEGIN BUTTON CUSTOMIZATION---
;

; Add a prefix to each of the below hotkeys to use a joystick other
; than the first.  For example: 2Joy1 is the second joystick's first
; mouse button.

Joy1:: ;Joystick Button 1
Send, {z down} ; Push and hold Z key
Loop
{
   Sleep, 10 ;Check Every 10 ms
   GetKeyState, joy1state, joy1 ; Is key up or down?
   if joy1state = U  ; The button has been released, so break out of the loop.
      break
}
Send, {z up} ; Release Z key
return

Joy2::
Send, {Space down}
Loop
{
   Sleep, 10
   GetKeyState, joy2state, joy2
   if joy2state = U
      break
}
Send, {Space up}
return

Joy3::
Send, {f down}
Loop
{
   Sleep, 10
   GetKeyState, joy3state, joy3
   if joy3state = U
      break
}
Send, {f up}
return


Joy4::
Send, {x down}
Loop
{
   Sleep, 10
   GetKeyState, joy4state, joy4
   if joy4state = U
      break
}
Send, {x up}
return

Joy5::
Send, {shiftdown}
Loop
{
   Sleep, 10
   GetKeyState, joy5state, joy5
   if joy5state = U   
      break
}
Send, {shiftup}
return

Joy6::
MouseClick, Middle, , , 1, ,D
Loop
{
   Sleep, 10
   GetKeyState, joy6state, joy6
   if joy6state = U
      break
}
MouseClick, Middle, , , , ,U
return

Joy7::
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, right, , , 1, 0, D  ; Hold down the right mouse button.
SetTimer, WaitForRightButtonUp, 10
return

Joy8::
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left, , , 1, 0, D  ; Hold down the left mouse button.
SetTimer, WaitForLeftButtonUp, 10
return

joy9::
Send, {Tab down}
Loop
{
   Sleep, 10
   GetKeyState, joy9state, joy9
   if joy9state = U
      break
}
Send, {Tab up}
return

joy10::
Send, {v down}
Loop
{
   Sleep, 10
   GetKeyState, joy10state, joy10
   if joy10state = U
      break
}
Send, {v up}
return

joy11::
Send, {Esc down}
Loop
{
   Sleep, 10
   GetKeyState, joy11state, joy11
   if joy11state = U
      break
}
Send, {Esc up}
return

joy12::
Send, {q down}
Loop
{
   Sleep, 10
   GetKeyState, joy12state, joy12
   if joy12state = U
      break
}
Send, {q up}
return

joy13::
Send, {e down}
Loop
{
   Sleep, 10
   GetKeyState, joy13state, joy13
   if joy13state = U
      break
}
Send, {e up}
return

;
; ---CHECK BUTTON STATES---
;

WaitForLeftButtonUp:
GetKeyState, jstate1, %JoystickNumber%Joy%ButtonLeft%
if jstate1 = D  ; The button is still, down, so keep waiting.
   return
; Otherwise, the button has been released.
SetTimer, WaitForLeftButtonUp, off
SetMouseDelay, -1  ; Makes movement smoother.
MouseClick, left, , , 1, 0, U  ; Release the mouse button.
return

WaitForRightButtonUp:
GetKeyState, jstate2, %JoystickNumber%Joy%ButtonRight%
if jstate2 = D
   return
; Otherwise, the button has been released.
SetTimer, WaitForRightButtonUp, off
MouseClick, right, , , 1, 0, U
return

;
; ---BEGIN JOYSTICK WATCH---
;

WatchJoystick:
MoveMouse? = n
MoveStick? = n
SetFormat, float, 03
GetKeyState, joyx, %JoystickNumber%joyx
GetKeyState, joyy, %JoystickNumber%joyy
GetKeyState, joyr, %JoystickNumber%joyr
GetKeyState, joyz, %JoystickNumber%joyz
GetKeyState, joypov, %JoystickNumber%joypov

;
; --- Left ANALOG JOYSTICK CONTROL ----
;

if joyx > %JoyThresholdUpper%
{
   MoveMouse? = y
   DeltaR = %joyx%
   DeltaR -= %JoyThresholdUpper%
}
else if joyx < %JoyThresholdLower%
{
   MoveMouse? = y
   DeltaR = %joyx%
   DeltaR -= %JoyThresholdLower%
}
else
   DeltaR = 0
if joyy > %JoyThresholdUpper%
{
   MoveMouse? = y
   DeltaZ = %joyy%
   DeltaZ -= %JoyThresholdUpper%
}
else if joyy < %JoyThresholdLower%
{
   MoveMouse? = y
   DeltaZ = %joyy%
   DeltaZ -= %JoyThresholdLower%
}
else
   DeltaZ = 0
if MoveMouse? = y
{
   DeltaR *= %JoyMultiplier%
   DeltaZ *= %JoyMultiplier%
   SetMouseDelay, -1  ; Makes movement smoother.
   MouseMove, %DeltaR%, %DeltaZ%, 0, R
}

;
; --- Right ANALOG JOYSTICK CONTROL ---
;

if joyr > %JoyThresholdUpper%
{
   MoveStick? = y
   DeltaX = %joyr%
   DeltaX -= %JoyThresholdUpper%
}
else if joyr < %JoyThresholdLower%
{
   MoveStick? = y
   DeltaX = %joyr%
   DeltaX -= %JoyThresholdLower%
}
else
   DeltaX = 0

if joyz > %JoyThresholdUpper%
{
   MoveStick? = y
   DeltaY = %joyz%
   DeltaY -= %JoyThresholdUpper%
}
else if joyz < %JoyThresholdLower%
{
   MoveStick? = y
   DeltaY = %joyz%
   DeltaY -= %JoyThresholdLower%
}
else
   DeltaY = 0

Code:


;; THIS IS THE AREA WITH THE ISSUE ;;


if MoveStick? = y
{
   DeltaX *= %JoyMultiplier%
   DeltaY *= %JoyMultiplier%
   if Deltay < 0
   {
      GetKeyState, astate, a
      if astate = U
      {
         Send, {left down} ; follow with {left up} - works but choppy
   return
      }
      GetKeyState, dstate, d
      if dstate = D
      {
         Send, {right up} ; doent work
   return
      }
   }
   else if Deltay > 0
   {
      GetKeyState, dstate, d
      if dstate = U
      {
         Send, {right down}
   return
      }
      GetKeyState, astate, a
      if astate = D
      {
         Send, {left up}
   return
      }
   }

   if Deltax < 0
   {
      GetKeyState, wstate, w
      if wstate = U
      {
         Send, {up down}
   return
      }
      GetKeyState, sstate, s
      if sstate = D
      {
         Send, {down up}
   return
      }
   }
   else if Deltax > 0
   {
      GetKeyState, sstate, s
      if sstate = U
      {
         Send, {down down}
   return
      }
      GetKeyState, wstate, w
      if wstate = D
      {
         Send, {up up}
   return
      }
   }
}

if Deltax = 0
{
   GetKeyState, wstate, w
   GetKeyState, sstate, s
   if wstate = D
   {
      Send, {up up}
   return
   }
   if sstate = D
   {
      Send, {down up}
   return
   }
}

if Deltay = 0
{
   GetKeyState, astate, a
   GetKeyState, dstate, d
   if astate = D
   {
      Send, {left up}
   return
   }
   else if dstate = D
   {
      Send, {right up}
   return
   }
}

Code:

;
; ---CONFIGURE DIRECTIONAL PAD---
;

if joypov = 0
Send, {w down}{a up}{d up}{s up}

if joypov = 4500
Send, {w down}{d down}{a up}{s up}

if joypov = 9000
Send, {d down}{w up}{s up}{a up}

if joypov = 13500
Send, {d down}{s down}{a up}{w up}

if joypov = 18000
Send, {s down}{a up}{d up}{w up}

if joypov = 22500
Send, {s down}{a down}{w up}{d up}

if joypov = 27000
Send, {a down}{w up}{s up}{d up}

if joypov = 31500
Send, {a down}{w down}{d up}{s up}

if joypov = -1
Send, {w up}{d up}{a up}{s up}

return


thanks for your help.
_________________
Thanks,

Cleaner


Last edited by Cleaner on Fri Apr 08, 2005 2:43 pm; edited 2 times in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Thu Apr 07, 2005 12:22 pm    Post subject: Reply with quote

I think the issue here is that when you want to combine two scripts, you should merge their auto-execute sections into one big section at the top of the script, then put all the subroutines and hotkeys underneath that section. For example, in your script the "POV to keyboard" will never execute because it's beneath other subroutines. So you might move that part of it that should run when the script starts to the top of the script. The rest can be left at the bottom, though you might have to (or at least want to) merge the two or more timers into one timer that watches the entire joystick.

The concept of the auto-execute section is simply that any commands that occur at the very top of the script get executed immediately when the script launches. There are more details at: http://www.autohotkey.com/docs/Scripts.htm
Back to top
View user's profile Send private message Send e-mail
Cleaner



Joined: 06 Oct 2004
Posts: 4

PostPosted: Fri Apr 08, 2005 2:47 pm    Post subject: Reply with quote

Thanks Chris, after reading through everything about 3 or 4 times, I figured it would be almost easier to go back to square one. I scrapped the previous script and pieced together the scripts above but I cant get the right analog (wasd) controlls to work.

I edited my post above for more detail. I have almost got it, just that one small issue.

Thanks again for your help.
_________________
Thanks,

Cleaner
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group