/docs/scripts/JoystickTest.htm

https://github.com/fincs/AutoHotkey_L-Docs · HTML · 107 lines · 100 code · 7 blank · 0 comment · 0 complexity · e70209cf6fc73bbfcf9abdb89fe28815 MD5 · raw file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Joystick Test Script</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  8. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  9. <script src="../static/jquery.js" type="text/javascript"></script>
  10. <script src="../static/tree.jquery.js" type="text/javascript"></script>
  11. <script src="../static/content.js" type="text/javascript"></script>
  12. </head>
  13. <body>
  14. <h1>Joystick Test Script</h1>
  15. <p>This script helps determine the button numbers and other attributes
  16. of your joystick. It might also reveal if your joystick is in need
  17. of calibration; that is, whether the range of motion of each of its
  18. axes is from 0 to 100 percent as it should be. If calibration is
  19. needed, use the operating system's control panel or the software
  20. that came with your joystick.
  21. </p>
  22. <p><a href="JoystickTest.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>
  23. <pre class="NoIndent"><em>; July 6, 2005: Added auto-detection of joystick number.
  24. ; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of
  25. ; detecting whether the joystick is connected. Some joysticks are
  26. ; gamepads and don't have even a single axis.</em>
  27. <em>; If you want to unconditionally use a specific joystick number, change
  28. ; the following value from 0 to the number of the joystick (1-16).
  29. ; A value of 0 causes the joystick number to be auto-detected:</em>
  30. JoystickNumber = 0
  31. <em>; END OF CONFIG SECTION. Do not make changes below this point unless
  32. ; you wish to alter the basic functionality of the script.</em>
  33. <em>; Auto-detect the joystick number if called for:</em>
  34. if JoystickNumber &lt;= 0
  35. {
  36. Loop 16 <em>; Query each joystick number to find out which ones exist.</em>
  37. {
  38. GetKeyState, JoyName, %A_Index%JoyName
  39. if JoyName &lt;&gt;
  40. {
  41. JoystickNumber = %A_Index%
  42. break
  43. }
  44. }
  45. if JoystickNumber &lt;= 0
  46. {
  47. MsgBox The system does not appear to have any joysticks.
  48. ExitApp
  49. }
  50. }
  51. #SingleInstance
  52. SetFormat, float, 03 <em>; Omit decimal point from axis position percentages.</em>
  53. GetKeyState, joy_buttons, %JoystickNumber%JoyButtons
  54. GetKeyState, joy_name, %JoystickNumber%JoyName
  55. GetKeyState, joy_info, %JoystickNumber%JoyInfo
  56. Loop
  57. {
  58. buttons_down =
  59. Loop, %joy_buttons%
  60. {
  61. GetKeyState, joy%a_index%, %JoystickNumber%joy%a_index%
  62. if joy%a_index% = D
  63. buttons_down = %buttons_down%%a_space%%a_index%
  64. }
  65. GetKeyState, joyx, %JoystickNumber%JoyX
  66. axis_info = X%joyx%
  67. GetKeyState, joyy, %JoystickNumber%JoyY
  68. axis_info = %axis_info%%a_space%%a_space%Y%joyy%
  69. IfInString, joy_info, Z
  70. {
  71. GetKeyState, joyz, %JoystickNumber%JoyZ
  72. axis_info = %axis_info%%a_space%%a_space%Z%joyz%
  73. }
  74. IfInString, joy_info, R
  75. {
  76. GetKeyState, joyr, %JoystickNumber%JoyR
  77. axis_info = %axis_info%%a_space%%a_space%R%joyr%
  78. }
  79. IfInString, joy_info, U
  80. {
  81. GetKeyState, joyu, %JoystickNumber%JoyU
  82. axis_info = %axis_info%%a_space%%a_space%U%joyu%
  83. }
  84. IfInString, joy_info, V
  85. {
  86. GetKeyState, joyv, %JoystickNumber%JoyV
  87. axis_info = %axis_info%%a_space%%a_space%V%joyv%
  88. }
  89. IfInString, joy_info, P
  90. {
  91. GetKeyState, joyp, %JoystickNumber%JoyPOV
  92. axis_info = %axis_info%%a_space%%a_space%POV%joyp%
  93. }
  94. ToolTip, %joy_name% (#%JoystickNumber%):`n%axis_info%`nButtons Down: %buttons_down%`n`n(right-click the tray icon to exit)
  95. Sleep, 100
  96. }
  97. return
  98. </pre>
  99. </body>
  100. </html>