Advertisement
Guest User

use any joystick with Ace Combat 7 - Skies Unknown

a guest
Feb 18th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; AHK script for Ace Combat 7 - Skies Unknown to allow use of any joystick.
  2. ; All the keys are default except machine gun and missile, add M and N in Options/Keyboard.
  3. ; my joystick is a Logitech Freedom 2.4, might need to customize for others.
  4.  
  5. #Persistent
  6.  
  7. SetTimer, CallAll, 5
  8. return
  9.  
  10. ; c chg weapon
  11. ; g flare
  12. ; f highlight target
  13. ; v chg view
  14. ; m shoot
  15. ; n missile
  16.  
  17. 2joy2:: send {n down}
  18. 2joy2 up:: send {n up}
  19.  
  20. 2joy5:: send {tab down}
  21. 2joy5 up:: send {tab up}
  22.  
  23. 2joy7:: send {g down}
  24. 2joy7 up:: send {g up}
  25.  
  26. 2joy9:: send {c down}
  27. 2joy9 up:: send {c up}
  28.  
  29. 2joy10:: send {v down}
  30. 2joy10 up:: send {v up}
  31.  
  32. CallAll:
  33. WatchAxis()
  34. WatchPOV()
  35. WatchRudder()
  36. WatchThrottle()
  37. WatchButtons()
  38. return
  39.  
  40. WatchButtons()
  41. {
  42.     static KeyToHoldDownPrev, KeyToHoldDown
  43.     GetKeyState, Joy1, 2Joy1
  44.     KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).
  45.  
  46.     if Joy1 = D
  47.         KeyToHoldDown = M
  48.     else
  49.         KeyToHoldDown =
  50.  
  51.     if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  52.         return  ; Do nothing.
  53.  
  54.     ; Otherwise, release the previous key and press down the new key:
  55.     SetKeyDelay -1  ; Avoid delays between keystrokes.
  56.     if KeyToHoldDownPrev   ; There is a previous key to release.
  57.         Send, {%KeyToHoldDownPrev% up}  ; Release it.
  58.     if KeyToHoldDown   ; There is a key to press down.
  59.         Send, {%KeyToHoldDown% down}  ; Press it down.
  60. }
  61.  
  62. WatchThrottle()
  63. {
  64.     static KeyToHoldDownPrev, KeyToHoldDown, PrevJoyZ
  65.     GetKeyState, JoyZ, 2JoyZ
  66.     JoyZ := Round(JoyZ)
  67.     KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).
  68.     if PrevJoyZ =
  69.         PrevJoyZ = %JoyZ%
  70.     if JoyZ < %PrevJoyZ%
  71.         KeyToHoldDown = W
  72.     else if JoyZ > %PrevJoyZ%
  73.         KeyToHoldDown = S
  74.     else
  75.         KeyToHoldDown =
  76.  
  77.     PrevJoyZ = %JoyZ%
  78.  
  79.     if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  80.         return  ; Do nothing.
  81.  
  82.     ; Otherwise, release the previous key and press down the new key:
  83.     SetKeyDelay -1  ; Avoid delays between keystrokes.
  84.     if KeyToHoldDownPrev   ; There is a previous key to release.
  85.         Send, {%KeyToHoldDownPrev% up}  ; Release it.
  86.     if KeyToHoldDown   ; There is a key to press down.
  87.         Send, {%KeyToHoldDown% down}  ; Press it down.
  88. }
  89.  
  90. WatchRudder()
  91. {
  92.     static KeyToHoldDownPrev, KeyToHoldDown
  93.     GetKeyState, JoyR, 2JoyR
  94.     KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).
  95.  
  96.     if JoyR < 10
  97.         KeyToHoldDown = Q
  98.     else if JoyR > 90
  99.         KeyToHoldDown = E
  100.     else
  101.         KeyToHoldDown =
  102.  
  103.     if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  104.         return  ; Do nothing.
  105.  
  106.     ; Otherwise, release the previous key and press down the new key:
  107.     SetKeyDelay -1  ; Avoid delays between keystrokes.
  108.     if KeyToHoldDownPrev   ; There is a previous key to release.
  109.         Send, {%KeyToHoldDownPrev% up}  ; Release it.
  110.     if KeyToHoldDown   ; There is a key to press down.
  111.         Send, {%KeyToHoldDown% down}  ; Press it down.
  112. }
  113.  
  114. WatchAxis()
  115. {
  116.     static KeyToHoldDownPrev, KeyToHoldDown
  117.     GetKeyState, JoyX, 2JoyX  ; Get position of X axis.
  118.     GetKeyState, JoyY, 2JoyY  ; Get position of Y axis.
  119.     KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).
  120.  
  121.     if JoyX > 60
  122.         KeyToHoldDown = D
  123.     else if JoyX < 40
  124.         KeyToHoldDown = A
  125.     else if JoyY > 60
  126.         KeyToHoldDown = 3
  127.     else if JoyY < 40
  128.         KeyToHoldDown = 1
  129.     else
  130.         KeyToHoldDown =
  131.  
  132.     if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  133.         return  ; Do nothing.
  134.  
  135.     ; Otherwise, release the previous key and press down the new key:
  136.     SetKeyDelay -1  ; Avoid delays between keystrokes.
  137.     if KeyToHoldDownPrev   ; There is a previous key to release.
  138.         Send, {%KeyToHoldDownPrev% up}  ; Release it.
  139.     if KeyToHoldDown   ; There is a key to press down.
  140.         Send, {%KeyToHoldDown% down}  ; Press it down.
  141. }
  142.  
  143. WatchPOV()
  144. {
  145.     static KeyToHoldDownPrev, KeyToHoldDown
  146.     GetKeyState, POV, 2JoyPOV  ; Get position of the POV control.
  147.     KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).
  148.  
  149.     ; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
  150.     ; To support them all, use a range:
  151.     if POV < 0   ; No angle to report
  152.         KeyToHoldDown =
  153.     else if POV > 31500                 ; 315 to 360 degrees: Forward
  154.         KeyToHoldDown = Numpad8
  155.     else if POV between 0 and 4500      ; 0 to 45 degrees: Forward
  156.         KeyToHoldDown = Numpad8
  157.     else if POV between 4501 and 13500  ; 45 to 135 degrees: Right
  158.         KeyToHoldDown = Numpad6
  159.     else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
  160.         KeyToHoldDown = Numpad2
  161.     else                                ; 225 to 315 degrees: Left
  162.         KeyToHoldDown = Numpad4
  163.  
  164.     if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  165.         return  ; Do nothing.
  166.  
  167.     ; Otherwise, release the previous key and press down the new key:
  168.     SetKeyDelay -1  ; Avoid delays between keystrokes.
  169.     if KeyToHoldDownPrev   ; There is a previous key to release.
  170.         Send, {%KeyToHoldDownPrev% up}  ; Release it.
  171.     if KeyToHoldDown   ; There is a key to press down.
  172.         Send, {%KeyToHoldDown% down}  ; Press it down.
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement