Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Starbound Joypad Test by Cragrim
- ; --- DECLARATIONS ---
- #Persistent
- #SingleInstance force
- #NoEnv
- SendMode Input
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- WheelDelay := 5 ;Milliseconds between keypad event
- MouseOffset := 300 ;Increase on higher screen resolutions, or decrease on lower resolutions
- ; Auto-detect the joystick number if called for:
- if JoystickNumber <= 0
- {
- Loop 16 ; Query each joystick number to find out which ones exist.
- {
- GetKeyState, JoyName, %A_Index%JoyName
- if JoyName <>
- {
- JoystickNumber = %A_Index%
- break
- }
- }
- if JoystickNumber <= 0
- {
- Msgbox No joypad was detected! Please connect a joypad and restart!
- ExitApp
- }
- }
- Msgbox Joypad was detected in slot %JoystickNumber%
- ;Declare timers for keydown events
- SetTimer DigitalPad, %WheelDelay%
- Hotkey %JoystickNumber%Joy1, JumpButtonDown, on
- Hotkey %JoystickNumber%Joy2, AttackButtonDown, on
- Hotkey %JoystickNumber%Joy6, InventoryNext, on
- Hotkey %JoystickNumber%Joy5, InventoryPrev, on
- return ; End of auto-execute section.
- ; --- KEY BINDINGS ---
- #IfWinActive ahk_class SDL_app
- DigitalPad:
- SetMouseDelay, -1 ; Makes movement smoother.
- GetKeyState, POV, %JoystickNumber%JoyPOV
- KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
- if WinActive("ahk_class SDL_app")
- {
- ; 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 ; UpLeft
- {
- KeyToHoldDown = W
- DllCall("SetCursorPos", int, (A_ScreenWidth/2-MouseOffset), int, (A_ScreenHeight/2-MouseOffset))
- }
- else if POV = 0 ; Up
- {
- KeyToHoldDown = W
- DllCall("SetCursorPos", int, (A_ScreenWidth/2), int, (A_ScreenHeight/2-MouseOffset))
- }
- else if POV = 4500 ; UpRight
- {
- KeyToHoldDown = D
- DllCall("SetCursorPos", int, (A_ScreenWidth/2+MouseOffset), int, (A_ScreenHeight/2-MouseOffset))
- }
- else if POV = 9000 ; Right
- {
- KeyToHoldDown = D
- DllCall("SetCursorPos", int, (A_ScreenWidth/2+MouseOffset), int, (A_ScreenHeight/2))
- }
- else if POV = 13500 ; DownRight
- {
- KeyToHoldDown = D
- DllCall("SetCursorPos", int, (A_ScreenWidth/2+MouseOffset), int, (A_ScreenHeight/2+MouseOffset))
- }
- else if POV = 18000 ; Down
- {
- KeyToHoldDown = S
- DllCall("SetCursorPos", int, (A_ScreenWidth/2), int, (A_ScreenHeight/2+MouseOffset))
- }
- else if POV = 22500 ; DownLeft
- {
- KeyToHoldDown = A
- DllCall("SetCursorPos", int, (A_ScreenWidth/2-MouseOffset), int, (A_ScreenHeight/2+MouseOffset))
- }
- else if POV = 27000 ; Left
- {
- KeyToHoldDown = A
- DllCall("SetCursorPos", int, (A_ScreenWidth/2-MouseOffset), int, (A_ScreenHeight/2))
- }
- if KeyToHoldDown = %KeyToHoldDownPrev% ; The correct key is already down (or no key is needed).
- return ; Do nothing.
- if KeyToHoldDownPrev ; There is a previous key to release.
- {
- Send, {%KeyToHoldDownPrev% up} ; Release it.
- }
- SetKeyDelay -1 ; Avoid delays between keystrokes.
- if KeyToHoldDown ; There is a key to press down.
- {
- Send, {%KeyToHoldDown% down} ; Press it down.
- }
- }
- return
- #IfWinActive ahk_class SDL_app
- JumpButtonDown:
- SetMouseDelay, -1 ; Makes movement smoother.
- Send, {Space Down}
- SetTimer, JumpButtonUp, 5
- return
- JumpButtonUp:
- if GetKeyState(JoystickNumber . "Joy1")
- return ; The button is still, down, so keep waiting.
- ; Otherwise, the button has been released.
- SetMouseDelay, -1 ; Makes movement smoother.
- SetTimer, JumpButtonUp, off ; Turn itself off
- Send, {Space Up}
- return
- #IfWinActive ahk_class SDL_app
- AttackButtonDown:
- SetMouseDelay, -1 ; Makes movement smoother.
- MouseClick, left,,, 1, 0, D ; Hold down the left mouse button.
- SetTimer, AttackButtonUp, 5
- return
- AttackButtonUp:
- if GetKeyState(JoystickNumber . "Joy2")
- return ; The button is still, down, so keep waiting.
- ; Otherwise, the button has been released.
- SetMouseDelay, -1 ; Makes movement smoother.
- SetTimer, AttackButtonUp, off ; Turn itself off
- MouseClick, left,,, 1, 0, U ; Release the mouse button.
- return
- #IfWinActive ahk_class SDL_app
- InventoryNext:
- SetMouseDelay, -1 ; Makes movement smoother.
- Send, {WheelDown}
- return
- #IfWinActive ahk_class SDL_app
- InventoryPrev:
- SetMouseDelay, -1 ; Makes movement smoother.
- Send, {WheelUp}
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement