Advertisement
RedFeatherMan

Spams a key, with a button on a controller being the toggle.

Aug 16th, 2022
1,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 21.17 KB | Gaming | 0 0
  1. ; There is somethings in here you may want to remove like the menu icons....
  2.  
  3. #SingleInstance, Force
  4. #Persistent
  5. #KeyHistory 0
  6. SetWorkingDir, %A_ScriptDir%
  7. SetBatchLines, -1
  8. ListLines, Off
  9. SetKeyDelay, -1, -1
  10. SetTitleMatchMode, 3
  11. SendMode, Input
  12. ;----------------------
  13. Menu, Tray, NoStandard
  14. Menu, Tray, Icon, setupapi, 56, 1
  15. Menu, ButtonsMenu, Add, Set Left Bumper, SetLeftBumper
  16. Menu, ButtonsMenu, Add, Set Right Bumper, SetRightBumper
  17. Menu, ButtonsMenu, Add, Set Y-Button, SetYButton
  18. Menu, ButtonsMenu, Add, Set X-Button, SetXButton
  19. Menu, ButtonsMenu, Add, Set B-Button, SetBButton
  20. Menu, ButtonsMenu, Add, Set A-Button, SetAButton
  21. Menu, ButtonsMenu, Add, Set Back Button, SetBackButton
  22. Menu, ButtonsMenu, Add, Set Start Button, SetStartButton
  23. Menu, ButtonsMenu, Add, Set Left Stick Click, SetLeftStick
  24. Menu, ButtonsMenu, Add, Set Right Stick Click, SetRightStick
  25. Menu, ButtonsMenu, Add, Set Up on DPAD, SetUpDPAD
  26. Menu, ButtonsMenu, Add, Set Down on DPAD, SetDownDPAD
  27. Menu, ButtonsMenu, Add, Set Left on DPAD, SetLeftDPAD
  28. Menu, ButtonsMenu, Add, Set Right on DPAD, SetRightDPAD
  29. Menu, Tray, Add, Buttons, :ButtonsMenu
  30. Menu, Tray, Add, &Reload, Reload
  31. Menu, Tray, Add, &Exit, Exit
  32. ;------------------------
  33. Menu, Tray, Icon, Buttons, %A_WorkingDir%\Lib\Ico\controller.ico,, 20
  34. Menu, ButtonsMenu, Icon, Set Left Bumper, %A_WorkingDir%\Lib\Ico\LBumper.ico,, 20
  35. Menu, ButtonsMenu, Icon, Set Right Bumper, %A_WorkingDir%\Lib\Ico\RBumper.ico,, 20
  36. Menu, ButtonsMenu, Icon, Set Y-Button, %A_WorkingDir%\Lib\Ico\Y.ico,, 20
  37. Menu, ButtonsMenu, Icon, Set X-Button, %A_WorkingDir%\Lib\Ico\X.ico,, 20
  38. Menu, ButtonsMenu, Icon, Set B-Button, %A_WorkingDir%\Lib\Ico\B.ico,, 20
  39. Menu, ButtonsMenu, Icon, Set A-Button, %A_WorkingDir%\Lib\Ico\A.ico,, 20
  40. Menu, ButtonsMenu, Icon, Set Back Button, %A_WorkingDir%\Lib\Ico\Home.ico,, 20
  41. Menu, ButtonsMenu, Icon, Set Start Button, %A_WorkingDir%\Lib\Ico\Home.ico,, 20
  42. Menu, ButtonsMenu, Icon, Set Left Stick Click, %A_WorkingDir%\Lib\Ico\LStick.ico,, 20
  43. Menu, ButtonsMenu, Icon, Set Right Stick Click, %A_WorkingDir%\Lib\Ico\RStick.ico,, 20
  44. Menu, ButtonsMenu, Icon, Set Up on DPAD, %A_WorkingDir%\Lib\Ico\DPAD.ico,, 20
  45. Menu, ButtonsMenu, Icon, Set Down on DPAD, %A_WorkingDir%\Lib\Ico\DPAD.ico,, 20
  46. Menu, ButtonsMenu, Icon, Set Left on DPAD, %A_WorkingDir%\Lib\Ico\DPAD.ico,, 20
  47. Menu, ButtonsMenu, Icon,Set Right on DPAD, %A_WorkingDir%\Lib\Ico\DPAD.ico,, 20
  48. ;----------------------
  49. loopToggle := 0
  50. Controller := 0
  51. lightFlaseTime := 35
  52. ;----------------------
  53. lBumper := 256
  54. rBumper := 512
  55. yButton := 32768
  56. xButton := 16384
  57. bButton := 8192
  58. aButton := 4096
  59. backButton := 32
  60. startButton := 16
  61. lStick := 64
  62. rStick := 128
  63. upDPAD := 1
  64. downDPAD := 2
  65. leftDPAD := 4
  66. rightDPAD := 8
  67. ;----------------------
  68. XInput_Init()
  69. CheckAndLoadSettings()
  70. LookForController()
  71. SetTimer, WaitForButton, 50
  72. return
  73. ;----------------------
  74. LookForController(){
  75.     Global
  76.     Controller = 0
  77.     if (Controller <= 0){
  78.         Loop 16
  79.         {
  80.             GetKeyState, JoyName, %A_Index%JoyName
  81.             if JoyName <>
  82.             {
  83.                 Controller = %A_Index%
  84.                 checkButton := toggleButton
  85.                 if (checkButton = 256){
  86.                     checkButton := "Left Bumper"
  87.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  88.                     break
  89.                 }              
  90.                 if (checkButton = 512){
  91.                     checkButton := "Right Bumper"
  92.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  93.                     break
  94.                 }                
  95.                 if (checkButton = 32768){
  96.                     checkButton := "Y-Button"
  97.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  98.                     break
  99.                 }                
  100.                 if (checkButton = 16384){
  101.                     checkButton := "X-Button"
  102.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  103.                     break                  
  104.                 }                
  105.                 if (checkButton = 8192){
  106.                     checkButton := "B-Button"
  107.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  108.                     break
  109.                 }                
  110.                 if (checkButton = 4096){
  111.                     checkButton := "A-Button"
  112.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  113.                     break
  114.                 }                
  115.                 if (checkButton = 32){
  116.                     checkButton := "Back Button"
  117.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  118.                     break
  119.                 }                
  120.                 if (checkButton = 16){
  121.                     checkButton := "Start Button"
  122.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  123.                     break
  124.                 }                
  125.                 if (checkButton = 64){
  126.                     checkButton := "Left Stick Click"
  127.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  128.                     break
  129.                 }                
  130.                 if (checkButton = 128){
  131.                     checkButton := "Right Stick Click"
  132.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  133.                     break
  134.                 }                
  135.                 if (checkButton = 1){
  136.                     checkButton := "Up on DPAD"
  137.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  138.                     break
  139.                 }                
  140.                 if (checkButton = 2){
  141.                     checkButton := "Down on DPAD"
  142.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  143.                     break
  144.                 }                
  145.                 if (checkButton = 4){
  146.                     checkButton := "Left on DPAD"
  147.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  148.                     break
  149.                 }                
  150.                 if (checkButton = 8){
  151.                     checkButton := "Right on DPAD"
  152.                     Msgbox, 0x41000, Flashy Lights, %checkButton% turns on and off Flashy Lights., 3
  153.                     break
  154.                 }
  155.             }
  156.         }
  157.         if (Controller <= 0){
  158.             MsgBox, 0x41000, Flashy Lights, This system does not appear to have any controllers. Plug in a controller and restart.
  159.             ExitApp
  160.         }
  161.     }
  162. }
  163.  
  164. CheckAndLoadSettings(){
  165.     Global
  166.     if FileExist(A_WorkingDir "\Lib\Settings.ini"){
  167.         IniRead, toggleButton, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button, %toggleButton%
  168.         if (toggleButton = ErrorLevel) || if (toggleButton = ""){
  169.             toggleButton := yButton
  170.         }
  171.     }else{
  172.         toggleButton := yButton
  173.     }
  174. }
  175.  
  176. SetLeftBumper(){
  177.     Global
  178.     toggleButton := lBumper
  179.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  180. }
  181.  
  182. SetRightBumper(){
  183.     Global
  184.     toggleButton := rBumper
  185.     InterpreteButtons()
  186.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  187.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  188.     SetTimer, RemoveTT, -4000
  189. }
  190.  
  191. SetYButton(){
  192.     Global
  193.     toggleButton := yButton
  194.     InterpreteButtons()
  195.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  196.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  197.     SetTimer, RemoveTT, -4000
  198. }
  199.  
  200. SetXButton(){
  201.     Global
  202.     toggleButton := xButton
  203.     InterpreteButtons()
  204.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  205.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  206.     SetTimer, RemoveTT, -4000
  207. }
  208.  
  209. SetBButton(){
  210.     Global
  211.     toggleButton := bButton
  212.     InterpreteButtons()
  213.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  214.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  215.     SetTimer, RemoveTT, -4000
  216. }
  217.  
  218. SetAButton(){
  219.     Global
  220.     toggleButton := aButton
  221.     InterpreteButtons()
  222.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  223.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  224.     SetTimer, RemoveTT, -4000
  225. }
  226.  
  227. SetBackButton(){
  228.     Global
  229.     toggleButton := backButton
  230.     InterpreteButtons()
  231.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  232.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  233.     SetTimer, RemoveTT, -4000
  234. }
  235.  
  236. SetStartButton(){
  237.     Global
  238.     toggleButton := startButton
  239.     InterpreteButtons()
  240.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  241.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  242.     SetTimer, RemoveTT, -4000
  243. }
  244.  
  245. SetLeftStick(){
  246.     Global
  247.     toggleButton := lStick
  248.     InterpreteButtons()
  249.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  250.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  251.     SetTimer, RemoveTT, -4000
  252. }
  253.  
  254. SetRightStick(){
  255.     Global
  256.     toggleButton := rStick
  257.     InterpreteButtons()
  258.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  259.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  260.     SetTimer, RemoveTT, -4000
  261. }
  262.  
  263. SetUpDPAD(){
  264.     Global
  265.     toggleButton := upDPAD
  266.     InterpreteButtons()
  267.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  268.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  269.     SetTimer, RemoveTT, -4000
  270. }
  271.  
  272. SetDownDPAD(){
  273.     Global
  274.     toggleButton := downDPAD
  275.     InterpreteButtons()
  276.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  277.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  278.     SetTimer, RemoveTT, -4000
  279. }
  280.  
  281. SetLeftDPAD(){
  282.     Global
  283.     toggleButton := leftDPAD
  284.     InterpreteButtons()
  285.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  286.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  287.     SetTimer, RemoveTT, -4000
  288. }
  289.  
  290. SetRightDPAD(){
  291.     Global
  292.     toggleButton := rightDPAD
  293.     InterpreteButtons()
  294.     IniWrite, %toggleButton%, %A_WorkingDir%\Lib\Settings.ini, Flashy Lights Toggle, Button
  295.     Msgbox, 0x41000, Flashy Lights, %checkButton% Will now be your button to toggle Flashy Lights on and off., 3
  296.     SetTimer, RemoveTT, -4000
  297. }
  298.  
  299. InterpreteButtons(){
  300.     Global
  301.     checkButton := toggleButton
  302.     if (checkButton = 256){
  303.         checkButton := "Left Bumper"
  304.     }              
  305.     if (checkButton = 512){
  306.         checkButton := "Right Bumper"
  307.     }                
  308.     if (checkButton = 32768){
  309.         checkButton := "Y-Button"
  310.     }                
  311.     if (checkButton = 16384){
  312.         checkButton := "X-Button"                
  313.     }                
  314.     if (checkButton = 8192){
  315.         checkButton := "B-Button"
  316.     }                
  317.     if (checkButton = 4096){
  318.         checkButton := "A-Button"
  319.     }                
  320.     if (checkButton = 32){
  321.         checkButton := "Back Button"
  322.     }                
  323.     if (checkButton = 16){
  324.         checkButton := "Start Button"
  325.     }                
  326.     if (checkButton = 64){
  327.         checkButton := "Left Stick Click"
  328.     }                
  329.     if (checkButton = 128){
  330.         checkButton := "Right Stick Click"
  331.     }                
  332.     if (checkButton = 1){
  333.         checkButton := "Up on DPAD"
  334.     }                
  335.     if (checkButton = 2){
  336.         checkButton := "Down on DPAD"
  337.     }                
  338.     if (checkButton = 4){
  339.         checkButton := "Left on DPAD"
  340.     }                
  341.     if (checkButton = 8){
  342.         checkButton := "Right on DPAD"
  343.     }
  344. }
  345. ;---------------------------
  346. WaitForButton:
  347. Loop
  348. {
  349.     Loop, 4
  350.     {
  351.         if State := XInput_GetState(A_Index-1) {
  352.             buttons := State.wButtons
  353.             if (buttons = toggleButton){
  354.                 if (loopToggle = 1){
  355.                     loopToggle := 0
  356.                     ToolTip, Stopped Flashing, MouseX, MouseY, 1
  357.                     SetTimer, RemoveTT, -3000
  358.                     DllCall("Sleep", "UInt", 100)
  359.                 }else{
  360.                     loopToggle := 1
  361.                     ToolTip, Flashing Lights, MouseX, MouseY, 1
  362.                     SetTimer, RemoveTT, -3000
  363.                     DllCall("Sleep", "UInt", 100)
  364.                 }          
  365.             }
  366.             if (loopToggle = 1){
  367.                 SendInput, {.}
  368.                 DllCall("Sleep", "UInt", lightFlaseTime)
  369.             }else{
  370.                 break
  371.             }
  372.         }
  373.     }
  374.     DllCall("Sleep", "UInt", 1)
  375. }
  376. return
  377.  
  378. RemoveTT:
  379. ToolTip
  380. return
  381.  
  382. Exit:
  383. ExitApp
  384.  
  385. Reload:
  386. Reload
  387. DllCall("Sleep", "UInt", 1000)
  388. GoTo, Exit
  389. return
  390. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  391. XInput_Init(dll="xinput1_3")
  392. {
  393.     global
  394.     if _XInput_hm
  395.         return
  396.    
  397.     ;======== CONSTANTS DEFINED IN XINPUT.H ========
  398.    
  399.     ; NOTE: These are based on my outdated copy of the DirectX SDK.
  400.     ;       Newer versions of XInput may require additional constants.
  401.    
  402.     ; Device types available in XINPUT_CAPABILITIES
  403.     XINPUT_DEVTYPE_GAMEPAD          := 0x01
  404.  
  405.     ; Device subtypes available in XINPUT_CAPABILITIES
  406.     XINPUT_DEVSUBTYPE_GAMEPAD       := 0x01
  407.  
  408.     ; Flags for XINPUT_CAPABILITIES
  409.     XINPUT_CAPS_VOICE_SUPPORTED     := 0x0004
  410.  
  411.     ; Constants for gamepad buttons
  412.     XINPUT_GAMEPAD_DPAD_UP          := 0x0001
  413.     XINPUT_GAMEPAD_DPAD_DOWN        := 0x0002
  414.     XINPUT_GAMEPAD_DPAD_LEFT        := 0x0004
  415.     XINPUT_GAMEPAD_DPAD_RIGHT       := 0x0008
  416.     XINPUT_GAMEPAD_START            := 0x0010
  417.     XINPUT_GAMEPAD_BACK             := 0x0020
  418.     XINPUT_GAMEPAD_LEFT_THUMB       := 0x0040
  419.     XINPUT_GAMEPAD_RIGHT_THUMB      := 0x0080
  420.     XINPUT_GAMEPAD_LEFT_SHOULDER    := 0x0100
  421.     XINPUT_GAMEPAD_RIGHT_SHOULDER   := 0x0200
  422.     XINPUT_GAMEPAD_A                := 0x1000
  423.     XINPUT_GAMEPAD_B                := 0x2000
  424.     XINPUT_GAMEPAD_X                := 0x4000
  425.     XINPUT_GAMEPAD_Y                := 0x8000
  426.  
  427.     ; Gamepad thresholds
  428.     XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE  := 7849
  429.     XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE := 8689
  430.     XINPUT_GAMEPAD_TRIGGER_THRESHOLD    := 30
  431.  
  432.     ; Flags to pass to XInputGetCapabilities
  433.     XINPUT_FLAG_GAMEPAD             := 0x00000001
  434.    
  435.     ;=============== END CONSTANTS =================
  436.    
  437.     _XInput_hm := DllCall("LoadLibrary" ,"str",dll)
  438.    
  439.     if !_XInput_hm
  440.     {
  441.         MsgBox, Failed to initialize XInput: %dll%.dll not found.
  442.         return
  443.     }
  444.    
  445.     _XInput_GetState        := DllCall("GetProcAddress" ,"ptr",_XInput_hm ,"astr","XInputGetState")
  446.     _XInput_SetState        := DllCall("GetProcAddress" ,"ptr",_XInput_hm ,"astr","XInputSetState")
  447.     _XInput_GetCapabilities := DllCall("GetProcAddress" ,"ptr",_XInput_hm ,"astr","XInputGetCapabilities")
  448.    
  449.     if !(_XInput_GetState && _XInput_SetState && _XInput_GetCapabilities)
  450.     {
  451.         XInput_Term()
  452.         MsgBox, Failed to initialize XInput: function not found.
  453.         return
  454.     }
  455. }
  456.  
  457. /*
  458.     Function: XInput_GetState
  459.    
  460.     Retrieves the current state of the specified controller.
  461.     Parameters:
  462.         UserIndex   -   [in] Index of the user's controller. Can be a value from 0 to 3.
  463.         State       -   [out] Receives the current state of the controller.
  464.    
  465.     Returns:
  466.         If the function succeeds, the return value is ERROR_SUCCESS (zero).
  467.         If the controller is not connected, the return value is ERROR_DEVICE_NOT_CONNECTED (1167).
  468.         If the function fails, the return value is an error code defined in Winerror.h.
  469.             http://msdn.microsoft.com/en-us/library/ms681381.aspx
  470.     Remarks:
  471.         XInput.dll returns controller state as a binary structure:
  472.             http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinput_state
  473.             http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinput_gamepad
  474.         XInput.ahk converts this structure to an AutoHotkey_L object.
  475. */
  476. XInput_GetState(UserIndex)
  477. {
  478.     global _XInput_GetState
  479.    
  480.     VarSetCapacity(xiState,16)
  481.  
  482.     if ErrorLevel := DllCall(_XInput_GetState ,"uint",UserIndex ,"uint",&xiState)
  483.         return 0
  484.    
  485.     return {
  486.     (Join,
  487.         dwPacketNumber: NumGet(xiState,  0, "UInt")
  488.         wButtons:      NumGet(xiState,  4, "UShort")
  489.         bLeftTrigger:  NumGet(xiState,  6, "UChar")
  490.         bRightTrigger: NumGet(xiState,  7, "UChar")
  491.         sThumbLX:      NumGet(xiState,  8, "Short")
  492.         sThumbLY:      NumGet(xiState, 10, "Short")
  493.         sThumbRX:      NumGet(xiState, 12, "Short")
  494.         sThumbRY:      NumGet(xiState, 14, "Short")
  495.     )}
  496. }
  497.  
  498. /*
  499.     Function: XInput_SetState
  500.    
  501.     Sends data to a connected controller. This function is used to activate the vibration
  502.     function of a controller.
  503.    
  504.     Parameters:
  505.         UserIndex       -   [in] Index of the user's controller. Can be a value from 0 to 3.
  506.         LeftMotorSpeed  -   [in] Speed of the left motor, between 0 and 65535.
  507.         RightMotorSpeed -   [in] Speed of the right motor, between 0 and 65535.
  508.    
  509.     Returns:
  510.         If the function succeeds, the return value is 0 (ERROR_SUCCESS).
  511.         If the controller is not connected, the return value is 1167 (ERROR_DEVICE_NOT_CONNECTED).
  512.         If the function fails, the return value is an error code defined in Winerror.h.
  513.             http://msdn.microsoft.com/en-us/library/ms681381.aspx
  514.    
  515.     Remarks:
  516.         The left motor is the low-frequency rumble motor. The right motor is the
  517.         high-frequency rumble motor. The two motors are not the same, and they create
  518.         different vibration effects.
  519. */
  520. XInput_SetState(UserIndex, LeftMotorSpeed, RightMotorSpeed)
  521. {
  522.     global _XInput_SetState
  523.     return DllCall(_XInput_SetState ,"uint",UserIndex ,"uint*",LeftMotorSpeed|RightMotorSpeed<<16)
  524. }
  525.  
  526. /*
  527.     Function: XInput_GetCapabilities
  528.    
  529.     Retrieves the capabilities and features of a connected controller.
  530.    
  531.     Parameters:
  532.         UserIndex   -   [in] Index of the user's controller. Can be a value in the range 0–3.
  533.         Flags       -   [in] Input flags that identify the controller type.
  534.                                 0   - All controllers.
  535.                                 1   - XINPUT_FLAG_GAMEPAD: Xbox 360 Controllers only.
  536.         Caps        -   [out] Receives the controller capabilities.
  537.    
  538.     Returns:
  539.         If the function succeeds, the return value is 0 (ERROR_SUCCESS).
  540.         If the controller is not connected, the return value is 1167 (ERROR_DEVICE_NOT_CONNECTED).
  541.         If the function fails, the return value is an error code defined in Winerror.h.
  542.             http://msdn.microsoft.com/en-us/library/ms681381.aspx
  543.    
  544.     Remarks:
  545.         XInput.dll returns capabilities via a binary structure:
  546.             http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinput_capabilities
  547.         XInput.ahk converts this structure to an AutoHotkey_L object.
  548. */
  549. XInput_GetCapabilities(UserIndex, Flags)
  550. {
  551.     global _XInput_GetCapabilities
  552.    
  553.     VarSetCapacity(xiCaps,20)
  554.    
  555.     if ErrorLevel := DllCall(_XInput_GetCapabilities ,"uint",UserIndex ,"uint",Flags ,"ptr",&xiCaps)
  556.         return 0
  557.    
  558.     return,
  559.     (Join
  560.         {
  561.             Type:                  NumGet(xiCaps,  0, "UChar"),
  562.             SubType:               NumGet(xiCaps,  1, "UChar"),
  563.             Flags:                 NumGet(xiCaps,  2, "UShort"),
  564.             Gamepad:
  565.            {
  566.                 wButtons:          NumGet(xiCaps,  4, "UShort"),
  567.                 bLeftTrigger:      NumGet(xiCaps,  6, "UChar"),
  568.                 bRightTrigger:     NumGet(xiCaps,  7, "UChar"),
  569.                 sThumbLX:          NumGet(xiCaps,  8, "Short"),
  570.                 sThumbLY:          NumGet(xiCaps, 10, "Short"),
  571.                 sThumbRX:          NumGet(xiCaps, 12, "Short"),
  572.                 sThumbRY:          NumGet(xiCaps, 14, "Short")
  573.             },
  574.             Vibration:
  575.            {
  576.                 wLeftMotorSpeed:   NumGet(xiCaps, 16, "UShort"),
  577.                 wRightMotorSpeed:  NumGet(xiCaps, 18, "UShort")
  578.             }
  579.         }
  580.     )
  581. }
  582.  
  583. /*
  584.     Function: XInput_Term
  585.     Unloads the previously loaded XInput DLL.
  586. */
  587. XInput_Term() {
  588.     global
  589.     if _XInput_hm
  590.         DllCall("FreeLibrary","uint",_XInput_hm), _XInput_hm :=_XInput_GetState :=_XInput_SetState :=_XInput_GetCapabilities :=0
  591. }
  592.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement