Advertisement
valdir_sensato

autohotkey joystick 2

Apr 23rd, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. #Persistent ; Keep this script running until the user explicitly exits it.
  3. #SingleInstance force
  4. SetKeyDelay -1
  5. turboDelay = 50
  6.  
  7. ; JOYSTICK 2
  8. ; joystick 2 - axis x, y
  9. joy2up = w
  10. joy2left = a
  11. joy2down = s
  12. joy2right = d
  13.  
  14. ; joystick 2 - buttons
  15. joy2b1 = Numpad4
  16. joy2b2 = Numpad6
  17. joy2b3 = Numpad0
  18. joy2b4 = Numpad5
  19. joy2b5 = Numpad8
  20. joy2b6 = Numpad0
  21. joy2b7 = NumpadAdd
  22. joy2b8 = Numpad1
  23. joy2b9 = Numpad9
  24. joy2b10 = esc
  25. joy2b11 = Numpad2
  26. joy2b12 = enter
  27.  
  28. ; joystick 2 - turbo button (true = yes, false = no)
  29. joy2b1turbo = true
  30. joy2b2turbo = false
  31. joy2b3turbo = false
  32. joy2b4turbo = true
  33. joy2b5turbo = false
  34. joy2b6turbo = false
  35. joy2b7turbo = false
  36. joy2b8turbo = false
  37. joy2b9turbo = false
  38. joy2b10turbo = false
  39. joy2b11turbo = false
  40. joy2b12turbo = false
  41.  
  42. ; joystick 2 - POV (Point Of View), D-PAD or PAD
  43. joy2PovUp := joy2up
  44. joy2PovLeft := joy2left
  45. joy2PovDown := joy2down
  46. joy2PovRight := joy2right
  47.  
  48. joy2PovIdle = -1 ; Only change if you are sure what you are doing.
  49. joy2PovUpNumber = 0 ; Only change if you are sure what you are doing.
  50. joy2PovLeftNumber = 27000 ; Only change if you are sure what you are doing.
  51. joy2PovDownNumber = 18000 ; Only change if you are sure what you are doing.
  52. joy2PovRightNumber = 9000 ; Only change if you are sure what you are doing.
  53.  
  54. j2direction := 1
  55.  
  56. SetTimer, WatchAxis2, 5
  57.  
  58. WatchAxis2:
  59. GetKeyState, 2JoyX, 2JoyX ; Get position of X axis.
  60. GetKeyState, 2JoyY, 2JoyY ; Get position of Y axis.
  61. GetKeyState, POV2, 2JoyPOV ; Get position of the POV control.
  62.  
  63. j2directionPrevious := j2direction
  64.  
  65. if (POV2 <> joy2PovIdle) {
  66.  
  67. ;diagonal - up + left
  68. if (POV2 > joy2PovLeftNumber) ; 31500
  69. {
  70. j2key1 := joy2PovUp
  71. j2key2 := joy2PovLeft
  72. j2direction := 1
  73. }
  74. ;left
  75. else if (POV2 = joy2PovLeftNumber) ; 27000
  76. {
  77. j2key1 := joy2PovLeft
  78. j2direction := 6
  79. }
  80. ;diagonal - down + left
  81. else if (POV2 > joy2PovDownNumber) ; 22500
  82. {
  83. j2key1 := joy2PovDown
  84. j2key2 := joy2PovLeft
  85. j2direction := 3
  86. }
  87. ;down
  88. else if (POV2 = joy2PovDownNumber) ; 18000
  89. {
  90. j2key1 := joy2PovDown
  91. j2direction := 7
  92. }
  93. ;diagonal - down + right
  94. else if (POV2 > joy2PovRightNumber) ; 13500
  95. {
  96. j2key1 := joy2PovDown
  97. j2key2 := joy2PovRight
  98. j2direction := 4
  99. }
  100. ;right
  101. else if (POV2 = joy2PovRightNumber) ; 9000
  102. {
  103. j2key1 := joy2PovRight
  104. j2direction := 5
  105. }
  106. ;diagonal - up + right
  107. else if (POV2 > joy2PovUpNumber) ; 4500
  108. {
  109. j2key1 := joy2PovUp
  110. j2key2 := joy2PovRight
  111. j2direction := 2
  112. }
  113. ;up
  114. else if (POV2 = joy2PovUpNumber) ; 0
  115. {
  116. j2key1 := joy2PovUp
  117. j2direction := 8
  118. }
  119. else
  120. {
  121. j2key1 =
  122. j2key2 =
  123. j2direction := 0
  124. }
  125.  
  126. }
  127. else
  128. {
  129.  
  130. ;diagonal - up + left
  131. if (2JoyY < 30) and (2JoyX < 30)
  132. {
  133. j2key1 := joy2up
  134. j2key2 := joy2left
  135. j2direction := 1
  136. }
  137. ;diagonal - up + right
  138. else if (2JoyY < 30) and (2JoyX > 70)
  139. {
  140. j2key1 := joy2up
  141. j2key2 := joy2right
  142. j2direction := 2
  143. }
  144. ;diagonal - down + left
  145. else if (2JoyY > 70) and (2JoyX < 30)
  146. {
  147. j2key1 := joy2down
  148. j2key2 := joy2left
  149. j2direction := 3
  150. }
  151. ;diagonal - down + right
  152. else if (2JoyY > 70) and (2JoyX > 70)
  153. {
  154. j2key1 := joy2down
  155. j2key2 := joy2right
  156. j2direction := 4
  157. }
  158. ;right
  159. else if 2JoyX > 70
  160. {
  161. j2key1 := joy2right
  162. j2direction := 5
  163. }
  164. ;left
  165. else if 2JoyX < 30
  166. {
  167. j2key1 := joy2left
  168. j2direction := 6
  169. }
  170. ;down
  171. else if 2JoyY > 70
  172. {
  173. j2key1 := joy2down
  174. j2direction := 7
  175. }
  176. ;up
  177. else if 2JoyY < 30
  178. {
  179. j2key1 := joy2up
  180. j2direction := 8
  181. }
  182. else
  183. {
  184. j2key1 =
  185. j2key2 =
  186. j2direction := 0
  187. }
  188.  
  189. }
  190.  
  191. if j2direction <> %j2directionPrevious%
  192. {
  193. Send, {%joy2up% up}
  194. Send, {%joy2left% up}
  195. Send, {%joy2down% up}
  196. Send, {%joy2right% up}
  197.  
  198. if (j2direction >= 1) and (j2direction <= 4)
  199. {
  200. Send, {%j2key1% down}
  201. Send, {%j2key2% down}
  202. }
  203. else
  204. {
  205. Send, {%j2key1% down}
  206. }
  207. }
  208.  
  209. return ; WatchAxis2 end
  210.  
  211. ; BUTTON 1
  212. ; joystick 2
  213. 2Joy1::
  214. if (%joy2b1turbo%) {
  215. loop { ; loop the script untill broken
  216. GetKeyState, state2Joy1, 2Joy1, P ; Get the state of button (U = Up and D = Down)
  217. if state2Joy1 = U
  218. break ; its been released so break the loop
  219. sleep, turboDelay
  220. send {%joy2b1% down}
  221. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  222. send {%joy2b1% up}
  223. } ;loop end
  224. } else {
  225. send {%joy2b1% down}
  226. KeyWait 2Joy1
  227. send {%joy2b1% up}
  228. } ; if end
  229. return
  230.  
  231. ; BUTTON 2
  232. ; joystick 2
  233. 2Joy2::
  234. if (%joy2b2turbo%) {
  235. loop { ; loop the script untill broken
  236. GetKeyState, state2Joy2, 2Joy2, P ; Get the state of button (U = Up and D = Down)
  237. if state2Joy2 = U
  238. break ; its been released so break the loop
  239. sleep, turboDelay
  240. send {%joy2b2% down}
  241. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  242. send {%joy2b2% up}
  243. } ;loop end
  244. } else {
  245. send {%joy2b2% down}
  246. KeyWait 2Joy2
  247. send {%joy2b2% up}
  248. } ; if end
  249. return
  250.  
  251. ; BUTTON 3
  252. ; joystick 2
  253. 2Joy3::
  254. if (%joy2b3turbo%) {
  255. loop { ; loop the script untill broken
  256. GetKeyState, state2Joy3, 2Joy3, P ; Get the state of button (U = Up and D = Down)
  257. if state2Joy3 = U
  258. break ; its been released so break the loop
  259. sleep, turboDelay
  260. send {%joy2b3% down}
  261. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  262. send {%joy2b3% up}
  263. } ;loop end
  264. } else {
  265. send {%joy2b3% down}
  266. KeyWait 2Joy3
  267. send {%joy2b3% up}
  268. } ; if end
  269. return
  270.  
  271. ; BUTTON 4
  272. ; joystick 2
  273. 2Joy4::
  274. if (%joy2b4turbo%) {
  275. loop { ; loop the script untill broken
  276. GetKeyState, state2Joy4, 2Joy4, P ; Get the state of button (U = Up and D = Down)
  277. if state2Joy4 = U
  278. break ; its been released so break the loop
  279. sleep, turboDelay
  280. send {%joy2b4% down}
  281. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  282. send {%joy2b4% up}
  283. } ;loop end
  284. } else {
  285. send {%joy2b4% down}
  286. KeyWait 2Joy4
  287. send {%joy2b4% up}
  288. } ; if end
  289. return
  290.  
  291. ; BUTTON 5
  292. ; joystick 2
  293. 2Joy5::
  294. if (%joy2b5turbo%) {
  295. loop { ; loop the script untill broken
  296. GetKeyState, state2Joy5, 2Joy5, P ; Get the state of button (U = Up and D = Down)
  297. if state2Joy5 = U
  298. break ; its been released so break the loop
  299. sleep, turboDelay
  300. send {%joy2b5% down}
  301. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  302. send {%joy2b5% up}
  303. } ;loop end
  304. } else {
  305. send {%joy2b5% down}
  306. KeyWait 2Joy5
  307. send {%joy2b5% up}
  308. } ; if end
  309. return
  310.  
  311. ; BUTTON 6
  312. ; joystick 2
  313. 2Joy6::
  314. if (%joy2b6turbo%) {
  315. loop { ; loop the script untill broken
  316. GetKeyState, state2Joy6, 2Joy6, P ; Get the state of button (U = Up and D = Down)
  317. if state2Joy6 = U
  318. break ; its been released so break the loop
  319. sleep, turboDelay
  320. send {%joy2b6% down}
  321. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  322. send {%joy2b6% up}
  323. } ;loop end
  324. } else {
  325. send {%joy2b6% down}
  326. KeyWait 2Joy6
  327. send {%joy2b6% up}
  328. } ; if end
  329. return
  330.  
  331. ; BUTTON 7
  332. ; joystick 2
  333. 2Joy7::
  334. if (%joy2b7turbo%) {
  335. loop { ; loop the script untill broken
  336. GetKeyState, state2Joy7, 2Joy7, P ; Get the state of button (U = Up and D = Down)
  337. if state2Joy7 = U
  338. break ; its been released so break the loop
  339. sleep, turboDelay
  340. send {%joy2b7% down}
  341. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  342. send {%joy2b7% up}
  343. } ;loop end
  344. } else {
  345. send {%joy2b7% down}
  346. KeyWait 2Joy7
  347. send {%joy2b7% up}
  348. } ; if end
  349. return
  350.  
  351. ; BUTTON 8
  352. ; joystick 2
  353. 2Joy8::
  354. if (%joy2b8turbo%) {
  355. loop { ; loop the script untill broken
  356. GetKeyState, state2Joy8, 2Joy8, P ; Get the state of button (U = Up and D = Down)
  357. if state2Joy8 = U
  358. break ; its been released so break the loop
  359. sleep, turboDelay
  360. send {%joy2b8% down}
  361. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  362. send {%joy2b8% up}
  363. } ;loop end
  364. } else {
  365. send {%joy2b8% down}
  366. KeyWait 2Joy8
  367. send {%joy2b8% up}
  368. } ; if end
  369. return
  370.  
  371. ; BUTTON 9
  372. ; joystick 2
  373. 2Joy9::
  374. if (%joy2b9turbo%) {
  375. loop { ; loop the script untill broken
  376. GetKeyState, state2Joy9, 2Joy9, P ; Get the state of button (U = Up and D = Down)
  377. if state2Joy9 = U
  378. break ; its been released so break the loop
  379. sleep, turboDelay
  380. send {%joy2b9% down}
  381. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  382. send {%joy2b9% up}
  383. } ;loop end
  384. } else {
  385. send {%joy2b9% down}
  386. KeyWait 2Joy9
  387. send {%joy2b9% up}
  388. } ; if end
  389. return
  390.  
  391. ; BUTTON 10
  392. ; joystick 2
  393. 2Joy10::
  394. if (%joy2b10turbo%) {
  395. loop { ; loop the script untill broken
  396. GetKeyState, state2Joy10, 2Joy10, P ; Get the state of button (U = Up and D = Down)
  397. if state2Joy10 = U
  398. break ; its been released so break the loop
  399. sleep, turboDelay
  400. send {%joy2b10% down}
  401. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  402. send {%joy2b10% up}
  403. } ;loop end
  404. } else {
  405. send {%joy2b10% down}
  406. KeyWait 2Joy10
  407. send {%joy2b10% up}
  408. } ; if end
  409. return
  410.  
  411. ; BUTTON 11
  412. ; joystick 2
  413. 2Joy11::
  414. if (%joy2b11turbo%) {
  415. loop { ; loop the script untill broken
  416. GetKeyState, state2Joy11, 2Joy11, P ; Get the state of button (U = Up and D = Down)
  417. if state2Joy11 = U
  418. break ; its been released so break the loop
  419. sleep, turboDelay
  420. send {%joy2b11% down}
  421. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  422. send {%joy2b11% up}
  423. } ;loop end
  424. } else {
  425. send {%joy2b11% down}
  426. KeyWait 2Joy11
  427. send {%joy2b11% up}
  428. } ; if end
  429. return
  430.  
  431. ; BUTTON 12
  432. ; joystick 2
  433. 2Joy12::
  434. if (%joy2b12turbo%) {
  435. loop { ; loop the script untill broken
  436. GetKeyState, state2Joy12, 2Joy12, P ; Get the state of button (U = Up and D = Down)
  437. if state2Joy12 = U
  438. break ; its been released so break the loop
  439. sleep, turboDelay
  440. send {%joy2b12% down}
  441. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  442. send {%joy2b12% up}
  443. } ;loop end
  444. } else {
  445. send {%joy2b12% down}
  446. KeyWait 2Joy12
  447. send {%joy2b12% up}
  448. } ; if end
  449. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement