Advertisement
icydeath-ffxi

ffxi_directinput.ahk

Jan 9th, 2021
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Run every line
  2. Critical
  3.  
  4. #SingleInstance force
  5.  
  6. ; Switch windows instantaeously
  7. SetWinDelay, -1
  8.  
  9. ; Avoid warning dialogue about over-hits
  10. #MaxHotkeysPerInterval 50000
  11. #HotkeyInterval 1
  12. #WinActivateForce
  13.  
  14. IniRead, ButtonLayout, config.ini, ButtonMap, ButtonLayout
  15. IniRead, ConfirmButton, config.ini, ButtonMap, ConfirmButton
  16. IniRead, CancelButton, config.ini, ButtonMap, CancelButton
  17. IniRead, MainMenuButton, config.ini, ButtonMap, MainMenuButton
  18. IniRead, ActiveWindowButton, config.ini, ButtonMap, ActiveWindowButton
  19. StringUpper, ButtonLayout, ButtonLayout
  20. StringUpper, ConfirmButton, ConfirmButton
  21. StringUpper, CancelButton, CancelButton
  22. StringUpper, MainMenuButton, MainMenuButton
  23. StringUpper, ActiveWindowButton, ActiveWindowButton
  24.  
  25. lastKeyPressed := ""
  26. isLeftTriggerDown := false
  27. isRightTriggerDown := false
  28. isDialogDown := false
  29.  
  30. #Persistent  ; Keep this script running until the user explicitly exits it.
  31. SetTimer, CheckPOVState, 10 ; Poll for POV hat every 10ms
  32.  
  33. CheckPOVState:
  34. If WinActive("ahk_class FFXiClass") {
  35.   If (isLeftTriggerDown or isRightTriggerDown or isDialogDown) {
  36.       GetKeyState, joyp, JoyPOV
  37.       If (joyp == 0) {
  38.         If (lastKeyPressed != "dpad_up") {
  39.           SendInput {f1}
  40.  
  41.           lastKeyPressed:= "dpad_up"
  42.         }
  43.       } else If (joyp == 9000) {
  44.         If (lastKeyPressed != "dpad_right") {
  45.           SendInput {f2}
  46.  
  47.           lastKeyPressed:= "dpad_right"
  48.         }
  49.       } else If (joyp == 18000) {
  50.         If (lastKeyPressed != "dpad_down") {
  51.           SendInput {f3}
  52.  
  53.           lastKeyPressed:= "dpad_down"
  54.         }
  55.       } else If (joyp == 27000) {
  56.         If (lastKeyPressed != "dpad_left") {
  57.           SendInput {f4}
  58.  
  59.           lastKeyPressed:= "dpad_left"
  60.         }
  61.       } else If (joyp == -1 and lastKeyPressed != "") {
  62.           lastKeyPressed:= ""
  63.       }
  64.     }
  65. }
  66. return
  67.  
  68. ; Helper subroutines. *DON'T* modify these to remap, instead just change which buttons call them
  69. SendConfirmKey:
  70. SendInput {Enter}
  71. return
  72. SendCancelKey:
  73. SendInput {Esc}
  74. return
  75. SendMainMenuKey:
  76. SendInput {NumpadSub}
  77. return
  78. SendActiveWindowKey:
  79. SendInput {NumpadAdd}
  80. return
  81.  
  82. ; Gamecube Y Button (Playstation Triangle, Xbox Y Button, Nintendo X Button, TOP face button)
  83. Joy4::
  84. If WinActive("ahk_class FFXiClass") {
  85.   If (isLeftTriggerDown or isRightTriggerDown) {
  86.     SendInput {f8}
  87.   } else {
  88.     If (ButtonLayout == "GAMECUBE" or ButtonLayout == "XBOX") {
  89.       If (ConfirmButton == "Y") {
  90.         Gosub, SendConfirmKey
  91.       } else If (CancelButton == "Y") {
  92.         Gosub, SendCancelKey
  93.       } else If (MainMenuButton == "Y") {
  94.         Gosub, SendMainMenuKey
  95.       } else If (ActiveWindowButton == "Y") {
  96.         Gosub, SendActiveWindowKey
  97.       }
  98.     } else If (ButtonLayout == "PLAYSTATION") {
  99.       If (ConfirmButton == "TRIANGLE") {
  100.         Gosub, SendConfirmKey
  101.       } else If (CancelButton == "TRIANGLE") {
  102.         Gosub, SendCancelKey
  103.       } else If (MainMenuButton == "TRIANGLE") {
  104.         Gosub, SendMainMenuKey
  105.       } else If (ActiveWindowButton == "TRIANGLE") {
  106.         Gosub, SendActiveWindowKey
  107.       }
  108.     } else If (ButtonLayout == "NINTENDO") {
  109.       If (ConfirmButton == "X") {
  110.         Gosub, SendConfirmKey
  111.       } else If (CancelButton == "X") {
  112.         Gosub, SendCancelKey
  113.       } else If (MainMenuButton == "X") {
  114.         Gosub, SendMainMenuKey
  115.       } else If (ActiveWindowButton == "X") {
  116.         Gosub, SendActiveWindowKey
  117.       }
  118.     }
  119.   }
  120. }
  121. return
  122.  
  123. ; Gamecube B Button (Playstation Square, Xbox X Button, Nintendo Y Button, LEFT face button)
  124. Joy1::
  125. If WinActive("ahk_class FFXiClass") {
  126.   If (isLeftTriggerDown or isRightTriggerDown) {
  127.     SendInput {f6}
  128.   } else {
  129.     If (ButtonLayout == "GAMECUBE") {
  130.       If (ConfirmButton == "B") {
  131.         Gosub, SendConfirmKey
  132.       } else If (CancelButton == "B") {
  133.         Gosub, SendCancelKey
  134.       } else If (MainMenuButton == "B") {
  135.         Gosub, SendMainMenuKey
  136.       } else If (ActiveWindowButton == "B") {
  137.         Gosub, SendActiveWindowKey
  138.       }
  139.     } else If (ButtonLayout == "XBOX") {
  140.       If (ConfirmButton == "X") {
  141.         Gosub, SendConfirmKey
  142.       } else If (CancelButton == "X") {
  143.         Gosub, SendCancelKey
  144.       } else If (MainMenuButton == "X") {
  145.         Gosub, SendMainMenuKey
  146.       } else If (ActiveWindowButton == "X") {
  147.         Gosub, SendActiveWindowKey
  148.       }
  149.     } else If (ButtonLayout == "PLAYSTATION") {
  150.       If (ConfirmButton == "SQUARE") {
  151.         Gosub, SendConfirmKey
  152.       } else If (CancelButton == "SQUARE") {
  153.         Gosub, SendCancelKey
  154.       } else If (MainMenuButton == "SQUARE") {
  155.         Gosub, SendMainMenuKey
  156.       } else If (ActiveWindowButton == "SQUARE") {
  157.         Gosub, SendActiveWindowKey
  158.       }
  159.     } else If (ButtonLayout == "NINTENDO") {
  160.       If (ConfirmButton == "Y") {
  161.         Gosub, SendConfirmKey
  162.       } else If (CancelButton == "Y") {
  163.         Gosub, SendCancelKey
  164.       } else If (MainMenuButton == "Y") {
  165.         Gosub, SendMainMenuKey
  166.       } else If (ActiveWindowButton == "Y") {
  167.         Gosub, SendActiveWindowKey
  168.       }
  169.     }
  170.   }
  171. }
  172. return
  173.  
  174. ; Gamecube A Button (Playstation Cross, Xbox A Button, Nintendo B Button, BOTTOM face button)
  175. Joy2::
  176. If WinActive("ahk_class FFXiClass") {
  177.   If (isLeftTriggerDown or isRightTriggerDown) {
  178.     SendInput {f5}
  179.   } else {
  180.     If (ButtonLayout == "GAMECUBE" or ButtonLayout == "XBOX") {
  181.       If (ConfirmButton == "A") {
  182.         Gosub, SendConfirmKey
  183.       } else If (CancelButton == "A") {
  184.         Gosub, SendCancelKey
  185.       } else If (MainMenuButton == "A") {
  186.         Gosub, SendMainMenuKey
  187.       } else If (ActiveWindowButton == "A") {
  188.         Gosub, SendActiveWindowKey
  189.       }
  190.     } else If (ButtonLayout == "PLAYSTATION") {
  191.       If (ConfirmButton == "CROSS") {
  192.         Gosub, SendConfirmKey
  193.       } else If (CancelButton == "CROSS") {
  194.         Gosub, SendCancelKey
  195.       } else If (MainMenuButton == "CROSS") {
  196.         Gosub, SendMainMenuKey
  197.       } else If (ActiveWindowButton == "CROSS") {
  198.         Gosub, SendActiveWindowKey
  199.       }
  200.     } else If (ButtonLayout == "NINTENDO") {
  201.       If (ConfirmButton == "B") {
  202.         Gosub, SendConfirmKey
  203.       } else If (CancelButton == "B") {
  204.         Gosub, SendCancelKey
  205.       } else If (MainMenuButton == "B") {
  206.         Gosub, SendMainMenuKey
  207.       } else If (ActiveWindowButton == "B") {
  208.         Gosub, SendActiveWindowKey
  209.       }
  210.     }
  211.   }
  212. }
  213. return
  214.  
  215. ; Gamecube X Button (Playstation Circle, Xbox B Button, Nintendo A Button, RIGHT face button)
  216. Joy3::
  217. If WinActive("ahk_class FFXiClass") {
  218.   If (isLeftTriggerDown or isRightTriggerDown) {
  219.     SendInput {f7}
  220.   } else {
  221.     If (ButtonLayout == "GAMECUBE") {
  222.       If (ConfirmButton == "X") {
  223.         Gosub, SendConfirmKey
  224.       } else If (CancelButton == "X") {
  225.         Gosub, SendCancelKey
  226.       } else If (MainMenuButton == "X") {
  227.         Gosub, SendMainMenuKey
  228.       } else If (ActiveWindowButton == "X") {
  229.         Gosub, SendActiveWindowKey
  230.       }
  231.     } else If (ButtonLayout == "XBOX") {
  232.       If (ConfirmButton == "B") {
  233.         Gosub, SendConfirmKey
  234.       } else If (CancelButton == "B") {
  235.         Gosub, SendCancelKey
  236.       } else If (MainMenuButton == "B") {
  237.         Gosub, SendMainMenuKey
  238.       } else If (ActiveWindowButton == "B") {
  239.         Gosub, SendActiveWindowKey
  240.       }
  241.     } else If (ButtonLayout == "PLAYSTATION") {
  242.       If (ConfirmButton == "CIRCLE") {
  243.         Gosub, SendConfirmKey
  244.       } else If (CancelButton == "CIRCLE") {
  245.         Gosub, SendCancelKey
  246.       } else If (MainMenuButton == "CIRCLE") {
  247.         Gosub, SendMainMenuKey
  248.       } else If (ActiveWindowButton == "CIRCLE") {
  249.         Gosub, SendActiveWindowKey
  250.       }
  251.     } else If (ButtonLayout == "NINTENDO") {
  252.       If (ConfirmButton == "A") {
  253.         Gosub, SendConfirmKey
  254.       } else If (CancelButton == "A") {
  255.         Gosub, SendCancelKey
  256.       } else If (MainMenuButton == "A") {
  257.         Gosub, SendMainMenuKey
  258.       } else If (ActiveWindowButton == "A") {
  259.         Gosub, SendActiveWindowKey
  260.       }
  261.     }
  262.   }
  263. }
  264. return
  265.  
  266. ; Left Trigger
  267. Joy7::
  268. If WinActive("ahk_class FFXiClass") {
  269.   SendInput {Ctrl down}
  270.   SendInput {f11 down}
  271.   isLeftTriggerDown := true
  272.   SetTimer, WaitForButtonUp7, 10 ; Poll for button setting every 10ms
  273. }
  274. return
  275.  
  276. WaitForButtonUp7:
  277. If WinActive("ahk_class FFXiClass") {
  278.   if GetKeyState("Joy7")  ; The button is still, down, so keep waiting.
  279.       return
  280.   ; Otherwise, the button has been released.
  281.   SendInput {f11 up}
  282.   if !isRightTriggerDown {
  283.     SendInput {Ctrl up}
  284.   }
  285.   isLeftTriggerDown := false
  286.   SetTimer, WaitForButtonUp7, Off ; Turn off polling
  287. }
  288. return
  289.  
  290. ; Right Trigger
  291. Joy8::
  292. If WinActive("ahk_class FFXiClass") {
  293.   SendInput {Ctrl down}
  294.   SendInput {f12 down}
  295.   isRightTriggerDown := true
  296.   SetTimer, WaitForButtonUp8, 10 ; Poll for button setting every 10ms
  297. }
  298. return
  299.  
  300. WaitForButtonUp8:
  301. If WinActive("ahk_class FFXiClass") {
  302.   if GetKeyState("Joy8")  ; The button is still, down, so keep waiting.
  303.       return
  304.   ; Otherwise, the button has been released.
  305.   SendInput {f12 up}
  306.   if !isLeftTriggerDown {
  307.     SendInput {Ctrl up}
  308.   }
  309.   isRightTriggerDown := false
  310.   SetTimer, WaitForButtonUp8, Off ; Turn off polling
  311. }
  312. return
  313.  
  314. ; Opens/closes gamepad binding dialog
  315. Joy9::
  316. If WinActive("ahk_class FFXiClass") {
  317.   SendInput {Ctrl down}
  318.   SendInput {f9 down}
  319.   SetTimer, WaitForButtonUp9, 10 ; Poll for button setting every 10ms
  320. }
  321. return
  322.  
  323. WaitForButtonUp9:
  324. If WinActive("ahk_class FFXiClass") {
  325.   if GetKeyState("Joy9")  ; The button is still, down, so keep waiting.
  326.       return
  327.   ; Otherwise, the button has been released.
  328.   SendInput {f9 up}
  329.   SendInput {Ctrl up}
  330.   SetTimer, WaitForButtonUp9, Off ; Turn off polling
  331. }
  332. return
  333.  
  334. ; Shows the environment list
  335. Joy10::
  336. If WinActive("ahk_class FFXiClass") {
  337.   SendInput {Ctrl down}
  338.   SendInput {f10 down}
  339.   isDialogDown := true
  340.   SetTimer, WaitForButtonUp10, 10 ; Poll for button setting every 10ms
  341. }
  342. return
  343.  
  344. WaitForButtonUp10:
  345. If WinActive("ahk_class FFXiClass") {
  346.   if GetKeyState("Joy10")  ; The button is still, down, so keep waiting.
  347.       return
  348.   ; Otherwise, the button has been released.
  349.   SendInput {f10 up}
  350.   SendInput {Ctrl up}
  351.   isDialogDown := false
  352.   SetTimer, WaitForButtonUp10, Off ; Turn off polling
  353. }
  354. return
  355.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement