Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; AHK script for Ace Combat 7 - Skies Unknown to allow use of any joystick.
- ; All the keys are default except machine gun and missile, add M and N in Options/Keyboard.
- ; my joystick is a Logitech Freedom 2.4, might need to customize for others.
- #Persistent
- SetTimer, CallAll, 5
- return
- ; c chg weapon
- ; g flare
- ; f highlight target
- ; v chg view
- ; m shoot
- ; n missile
- 2joy2:: send {n down}
- 2joy2 up:: send {n up}
- 2joy5:: send {tab down}
- 2joy5 up:: send {tab up}
- 2joy7:: send {g down}
- 2joy7 up:: send {g up}
- 2joy9:: send {c down}
- 2joy9 up:: send {c up}
- 2joy10:: send {v down}
- 2joy10 up:: send {v up}
- CallAll:
- WatchAxis()
- WatchPOV()
- WatchRudder()
- WatchThrottle()
- WatchButtons()
- return
- WatchButtons()
- {
- static KeyToHoldDownPrev, KeyToHoldDown
- GetKeyState, Joy1, 2Joy1
- KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
- if Joy1 = D
- KeyToHoldDown = M
- 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.
- }
- WatchThrottle()
- {
- static KeyToHoldDownPrev, KeyToHoldDown, PrevJoyZ
- GetKeyState, JoyZ, 2JoyZ
- JoyZ := Round(JoyZ)
- KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
- if PrevJoyZ =
- PrevJoyZ = %JoyZ%
- if JoyZ < %PrevJoyZ%
- KeyToHoldDown = W
- else if JoyZ > %PrevJoyZ%
- KeyToHoldDown = S
- else
- KeyToHoldDown =
- PrevJoyZ = %JoyZ%
- 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.
- }
- WatchRudder()
- {
- static KeyToHoldDownPrev, KeyToHoldDown
- GetKeyState, JoyR, 2JoyR
- KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
- if JoyR < 10
- KeyToHoldDown = Q
- else if JoyR > 90
- KeyToHoldDown = E
- 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.
- }
- WatchAxis()
- {
- static KeyToHoldDownPrev, KeyToHoldDown
- GetKeyState, JoyX, 2JoyX ; Get position of X axis.
- GetKeyState, JoyY, 2JoyY ; Get position of Y axis.
- KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
- if JoyX > 60
- KeyToHoldDown = D
- else if JoyX < 40
- KeyToHoldDown = A
- else if JoyY > 60
- KeyToHoldDown = 3
- else if JoyY < 40
- KeyToHoldDown = 1
- 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.
- }
- WatchPOV()
- {
- static KeyToHoldDownPrev, KeyToHoldDown
- GetKeyState, POV, 2JoyPOV ; 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 = Numpad8
- else if POV between 0 and 4500 ; 0 to 45 degrees: Forward
- KeyToHoldDown = Numpad8
- else if POV between 4501 and 13500 ; 45 to 135 degrees: Right
- KeyToHoldDown = Numpad6
- else if POV between 13501 and 22500 ; 135 to 225 degrees: Down
- KeyToHoldDown = Numpad2
- else ; 225 to 315 degrees: Left
- KeyToHoldDown = Numpad4
- 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.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement