Advertisement
valdir_sensato

autohotkey joystick 1

Apr 23rd, 2020
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.90 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 1
  8. ; joystick 1 - axis x, y
  9. ; setas_teclado
  10. ; Se true será usado as setas do teclado
  11. ; Se false você terá que personalizar do seu jeito, o padrão é wasd
  12. setas_teclado = true
  13.  
  14. joy1up = w
  15. joy1left = a
  16. joy1down = s
  17. joy1right = d
  18.  
  19. ; joystick 1 - buttons
  20. joy1b1 = Numpad1
  21. joy1b2 = k
  22. joy1b3 = space
  23. joy1b4 = j
  24. joy1b5 = o
  25. joy1b6 = b
  26. joy1b7 = u
  27. joy1b8 = space
  28. joy1b9 = i
  29. joy1b10 = esc
  30. joy1b11 = n
  31. joy1b12 = enter
  32.  
  33. ; joystick 1 - turbo button (true = yes, false = no)
  34. joy1b1turbo = false
  35. joy1b2turbo = false
  36. joy1b3turbo = false
  37. joy1b4turbo = false
  38. joy1b5turbo = false
  39. joy1b6turbo = false
  40. joy1b7turbo = false
  41. joy1b8turbo = false
  42. joy1b9turbo = false
  43. joy1b10turbo = false
  44. joy1b11turbo = false
  45. joy1b12turbo = false
  46.  
  47. ; joystick 1 - POV (Point Of View), D-PAD or PAD
  48. joy1PovUp := joy1up
  49. joy1PovLeft := joy1left
  50. joy1PovDown := joy1down
  51. joy1PovRight := joy1right
  52.  
  53. joy1PovIdle = -1 ; Only change if you are sure what you are doing.
  54. joy1PovUpNumber = 0 ; Only change if you are sure what you are doing.
  55. joy1PovLeftNumber = 27000 ; Only change if you are sure what you are doing.
  56. joy1PovDownNumber = 18000 ; Only change if you are sure what you are doing.
  57. joy1PovRightNumber = 9000 ; Only change if you are sure what you are doing.
  58.  
  59. j1direction := 1
  60.  
  61. ; Calling a steam game
  62. ;caminho = %A_ProgramFiles%\Steam\Steam.exe
  63. ;IfNotExist % caminho
  64. ;{
  65. ; caminho = %A_ProgramFiles% (x86)\Steam\Steam.exe
  66. ;}
  67. ;
  68. ;IfExist % caminho
  69. ;{
  70. ; Run %caminho% -applaunch 422810
  71. ;}
  72.  
  73. SetTimer, WatchAxis, 5
  74.  
  75. ; Quits script automatically when the game is finished
  76. ;Process, Wait, RCRU.exe
  77. ;Process, Exist, RCRU.exe
  78. ;PID = %ErrorLevel%
  79. ;Process, WaitClose, %PID%
  80. ;ExitApp
  81.  
  82. WatchAxis:
  83. GetKeyState, JoyX, JoyX ; Get position of X axis.
  84. GetKeyState, JoyY, JoyY ; Get position of Y axis.
  85. GetKeyState, POV, JoyPOV ; Get position of the POV control.
  86.  
  87. j1directionPrevious := j1direction
  88.  
  89. if (POV <> joy1PovIdle) {
  90.  
  91. ;diagonal - up + left
  92. if (POV > joy1PovLeftNumber) ; 31500
  93. {
  94. j1key1 := joy1PovUp
  95. j1key2 := joy1PovLeft
  96. j1direction := 1
  97. }
  98. ;left
  99. else if (POV = joy1PovLeftNumber) ; 27000
  100. {
  101. j1key1 := joy1PovLeft
  102. j1direction := 6
  103. }
  104. ;diagonal - down + left
  105. else if (POV > joy1PovDownNumber) ; 22500
  106. {
  107. j1key1 := joy1PovDown
  108. j1key2 := joy1PovLeft
  109. j1direction := 3
  110. }
  111. ;down
  112. else if (POV = joy1PovDownNumber) ; 18000
  113. {
  114. j1key1 := joy1PovDown
  115. j1direction := 7
  116. }
  117. ;diagonal - down + right
  118. else if (POV > joy1PovRightNumber) ; 13500
  119. {
  120. j1key1 := joy1PovDown
  121. j1key2 := joy1PovRight
  122. j1direction := 4
  123. }
  124. ;right
  125. else if (POV = joy1PovRightNumber) ; 9000
  126. {
  127. j1key1 := joy1PovRight
  128. j1direction := 5
  129. }
  130. ;diagonal - up + right
  131. else if (POV > joy1PovUpNumber) ; 4500
  132. {
  133. j1key1 := joy1PovUp
  134. j1key2 := joy1PovRight
  135. j1direction := 2
  136. }
  137. ;up
  138. else if (POV = joy1PovUpNumber) ; 0
  139. {
  140. j1key1 := joy1PovUp
  141. j1direction := 8
  142. }
  143. else
  144. {
  145. j1key1 =
  146. j1key2 =
  147. j1direction := 0
  148. }
  149.  
  150. }
  151. else
  152. {
  153.  
  154. ;diagonal - up + left
  155. if (JoyY < 30) and (JoyX < 30)
  156. {
  157. j1key1 := joy1up
  158. j1key2 := joy1left
  159. j1direction := 1
  160. }
  161. ;diagonal - up + right
  162. else if (JoyY < 30) and (JoyX > 70)
  163. {
  164. j1key1 := joy1up
  165. j1key2 := joy1right
  166. j1direction := 2
  167. }
  168. ;diagonal - down + left
  169. else if (JoyY > 70) and (JoyX < 30)
  170. {
  171. j1key1 := joy1down
  172. j1key2 := joy1left
  173. j1direction := 3
  174. }
  175. ;diagonal - down + right
  176. else if (JoyY > 70) and (JoyX > 70)
  177. {
  178. j1key1 := joy1down
  179. j1key2 := joy1right
  180. j1direction := 4
  181. }
  182. ;right
  183. else if JoyX > 70
  184. {
  185. j1key1 := joy1right
  186. j1direction := 5
  187. }
  188. ;left
  189. else if JoyX < 30
  190. {
  191. j1key1 := joy1left
  192. j1direction := 6
  193. }
  194. ;down
  195. else if JoyY > 70
  196. {
  197. j1key1 := joy1down
  198. j1direction := 7
  199. }
  200. ;up
  201. else if JoyY < 30
  202. {
  203. j1key1 := joy1up
  204. j1direction := 8
  205. }
  206. else
  207. {
  208. j1key1 =
  209. j1key2 =
  210. j1direction := 0
  211. }
  212.  
  213. }
  214.  
  215. if j1direction <> %j1directionPrevious%
  216. {
  217. if(%setas_teclado%){
  218. Send, {up up}
  219. Send, {left up}
  220. Send, {down up}
  221. Send, {right up}
  222.  
  223. if(j1direction = 5){
  224. Send, {right down}
  225. }else if(j1direction = 6){
  226. Send, {left down}
  227. }else if(j1direction = 8){
  228. Send, {up down}
  229. }else if(j1direction = 7){
  230. Send, {down down}
  231. }else if(j1direction = 2){
  232. Send, {up down}
  233. Send, {right down}
  234. }else if(j1direction = 1){
  235. Send, {up down}
  236. Send, {left down}
  237. }else if(j1direction = 4){
  238. Send, {right down}
  239. Send, {down down}
  240. }else if(j1direction = 3){
  241. Send, {left down}
  242. Send, {down down}
  243. }
  244.  
  245. } else {
  246. Send, {%joy1up% up}
  247. Send, {%joy1left% up}
  248. Send, {%joy1down% up}
  249. Send, {%joy1right% up}
  250.  
  251. ;se for uma diagonal
  252. if (j1direction >= 1) and (j1direction <= 4) {
  253. Send, {%j1key1% down}
  254. Send, {%j1key2% down}
  255. } else {
  256. Send, {%j1key1% down}
  257. }
  258. }
  259. }
  260.  
  261. return ; WatchAxis end
  262.  
  263.  
  264. ; BUTTON 1
  265. Joy1::
  266. if (%joy1b1turbo%) {
  267. loop { ; loop the script untill broken
  268. GetKeyState, stateJoy1, Joy1, P ; Get the state of button (U = Up and D = Down)
  269. if stateJoy1 = U
  270. break ; its been released so break the loop
  271. sleep, turboDelay
  272. send {%joy1b1% down}
  273. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  274. send {%joy1b1% up}
  275. } ;loop end
  276. } else {
  277. send {%joy1b1% down}
  278. KeyWait Joy1
  279. send {%joy1b1% up}
  280. } ; if end
  281. return
  282.  
  283. ; BUTTON 2
  284. ; joystick 1
  285. Joy2::
  286. if (%joy1b2turbo%) {
  287. loop { ; loop the script untill broken
  288. GetKeyState, stateJoy2, Joy2, P ; Get the state of button (U = Up and D = Down)
  289. if stateJoy2 = U
  290. break ; its been released so break the loop
  291. sleep, turboDelay
  292. send {%joy1b2% down}
  293. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  294. send {%joy1b2% up}
  295. } ;loop end
  296. } else {
  297. send {%joy1b2% down}
  298. KeyWait Joy2
  299. send {%joy1b2% up}
  300. } ; if end
  301. return
  302.  
  303. ; BUTTON 3
  304. ; joystick 1
  305. Joy3::
  306. if (%joy1b3turbo%) {
  307. loop { ; loop the script untill broken
  308. GetKeyState, stateJoy3, Joy3, P ; Get the state of button (U = Up and D = Down)
  309. if stateJoy3 = U
  310. break ; its been released so break the loop
  311. sleep, turboDelay
  312. send {%joy1b3% down}
  313. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  314. send {%joy1b3% up}
  315. } ;loop end
  316. } else {
  317. send {%joy1b3% down}
  318. KeyWait Joy3
  319. send {%joy1b3% up}
  320. } ; if end
  321. return
  322.  
  323. ; BUTTON 4
  324. Joy4::
  325. if (%joy1b4turbo%) {
  326. loop { ; loop the script untill broken
  327. GetKeyState, stateJoy4, Joy4, P ; Get the state of button (U = Up and D = Down)
  328. if stateJoy4 = U
  329. break ; its been released so break the loop
  330. sleep, turboDelay
  331. send {%joy1b4% down}
  332. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  333. send {%joy1b4% up}
  334. } ;loop end
  335. } else {
  336. send {%joy1b4% down}
  337. KeyWait Joy4
  338. send {%joy1b4% up}
  339. } ; if end
  340. return
  341.  
  342. ; BUTTON 5
  343. ; joystick 1
  344. Joy5::
  345. if (%joy1b5turbo%) {
  346. loop { ; loop the script untill broken
  347. GetKeyState, stateJoy5, Joy5, P ; Get the state of button (U = Up and D = Down)
  348. if stateJoy5 = U
  349. break ; its been released so break the loop
  350. sleep, turboDelay
  351. send {%joy1b5% down}
  352. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  353. send {%joy1b5% up}
  354. } ;loop end
  355. } else {
  356. send {%joy1b5% down}
  357. KeyWait Joy5
  358. send {%joy1b5% up}
  359. } ; if end
  360. return
  361.  
  362. ; BUTTON 6
  363. ; joystick 1
  364. Joy6::
  365. if (%joy1b6turbo%) {
  366. loop { ; loop the script untill broken
  367. GetKeyState, stateJoy6, Joy6, P ; Get the state of button (U = Up and D = Down)
  368. if stateJoy6 = U
  369. break ; its been released so break the loop
  370. sleep, turboDelay
  371. send {%joy1b6% down}
  372. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  373. send {%joy1b6% up}
  374. } ;loop end
  375. } else {
  376. send {%joy1b6% down}
  377. KeyWait Joy6
  378. send {%joy1b6% up}
  379. } ; if end
  380. return
  381.  
  382. ; BUTTON 7
  383. ; joystick 1
  384. Joy7::
  385. if (%joy1b7turbo%) {
  386. loop { ; loop the script untill broken
  387. GetKeyState, stateJoy7, Joy7, P ; Get the state of button (U = Up and D = Down)
  388. if stateJoy7 = U
  389. break ; its been released so break the loop
  390. sleep, turboDelay
  391. send {%joy1b7% down}
  392. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  393. send {%joy1b7% up}
  394. } ;loop end
  395. } else {
  396. send {%joy1b7% down}
  397. KeyWait Joy7
  398. send {%joy1b7% up}
  399. } ; if end
  400. return
  401.  
  402. ; BUTTON 8
  403. ; joystick 1
  404. Joy8::
  405. if (%joy1b8turbo%) {
  406. loop { ; loop the script untill broken
  407. GetKeyState, stateJoy8, Joy8, P ; Get the state of button (U = Up and D = Down)
  408. if stateJoy8 = U
  409. break ; its been released so break the loop
  410. sleep, turboDelay
  411. send {%joy1b8% down}
  412. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  413. send {%joy1b8% up}
  414. } ;loop end
  415. } else {
  416. send {%joy1b8% down}
  417. KeyWait Joy8
  418. send {%joy1b8% up}
  419. } ; if end
  420. return
  421.  
  422. ; BUTTON 9
  423. ; joystick 1
  424. Joy9::
  425. if (%joy1b9turbo%) {
  426. loop { ; loop the script untill broken
  427. GetKeyState, stateJoy9, Joy9, P ; Get the state of button (U = Up and D = Down)
  428. if stateJoy9 = U
  429. break ; its been released so break the loop
  430. sleep, turboDelay
  431. send {%joy1b9% down}
  432. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  433. send {%joy1b9% up}
  434. } ;loop end
  435. } else {
  436. send {%joy1b9% down}
  437. KeyWait Joy9
  438. send {%joy1b9% up}
  439. } ; if end
  440. return
  441.  
  442. ; BUTTON 10
  443. ; joystick 1
  444. Joy10::
  445. if (%joy1b10turbo%) {
  446. loop { ; loop the script untill broken
  447. GetKeyState, stateJoy10, Joy10, P ; Get the state of button (U = Up and D = Down)
  448. if stateJoy10 = U
  449. break ; its been released so break the loop
  450. sleep, turboDelay
  451. send {%joy1b10% down}
  452. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  453. send {%joy1b10% up}
  454. } ;loop end
  455. } else {
  456. send {%joy1b10% down}
  457. KeyWait Joy10
  458. send {%joy1b10% up}
  459. } ; if end
  460. return
  461.  
  462. ; BUTTON 11
  463. ; joystick 1
  464. Joy11::
  465. if (%joy1b11turbo%) {
  466. loop { ; loop the script untill broken
  467. GetKeyState, stateJoy11, Joy11, P ; Get the state of button (U = Up and D = Down)
  468. if stateJoy11 = U
  469. break ; its been released so break the loop
  470. sleep, turboDelay
  471. send {%joy1b11% down}
  472. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  473. send {%joy1b11% up}
  474. } ;loop end
  475. } else {
  476. send {%joy1b11% down}
  477. KeyWait Joy11
  478. send {%joy1b11% up}
  479. } ; if end
  480. return
  481.  
  482. ; BUTTON 12
  483. ; joystick 1
  484. Joy12::
  485. if (%joy1b12turbo%) {
  486. loop { ; loop the script untill broken
  487. GetKeyState, stateJoy12, Joy12, P ; Get the state of button (U = Up and D = Down)
  488. if stateJoy12 = U
  489. break ; its been released so break the loop
  490. sleep, turboDelay
  491. send {%joy1b12% down}
  492. sleep, turboDelay ; This is the time between presses, after its slept it will return to the top of the loop and start again
  493. send {%joy1b12% up}
  494. } ;loop end
  495. } else {
  496. send {%joy1b12% down}
  497. KeyWait Joy12
  498. send {%joy1b12% up}
  499. } ; if end
  500. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement