Advertisement
Mangus875

Precise steering v3

Feb 27th, 2025 (edited)
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; TODO: lock steerDir while holding 2 action keys
  2.  
  3. #Requires AutoHotkey v2.0
  4. #SingleInstance
  5.  
  6. SetKeyDelay 0, 0
  7. A_HotkeyInterval := 0
  8. SendMode "input"
  9. CoordMode "tooltip", "screen"
  10.  
  11. !X::ExitApp
  12. !R::Reload
  13. #UseHook 1
  14.  
  15. keys := ["1", "2", "3", "4", "5"]
  16. ak := [0,0,0,0,0]
  17. lastAk := 0
  18.  
  19. i:: {
  20.     global
  21.     showInfo()
  22. }
  23.  
  24. *1:: {
  25.     global
  26.     setAk(1)
  27.     KeyWait "1"
  28.     setAk(5)
  29.     lastAk := 0
  30. }
  31. *2:: {
  32.     global
  33.     setAk(2)
  34.     KeyWait "2"
  35.     setAk(5)
  36.     lastAk := 0
  37. }
  38. *3:: {
  39.     global
  40.     setAk(3)
  41.     KeyWait "3"
  42.     setAk(5)
  43.     lastAk := 0
  44. }
  45. *4:: {
  46.     global
  47.     setAk(4)
  48.     KeyWait "4"
  49.     setAk(5)
  50.     lastAk := 0
  51. }
  52. *5:: {
  53.     global
  54.     setAk(5)
  55.     KeyWait "5"
  56.     setAk(5)
  57.     lastAk := 0
  58. }
  59.  
  60.  
  61. SetTimer(updateKeys, 100)
  62.  
  63. Left:: {
  64.     global
  65.     steerDir := -1
  66.     KeyWait "Left"
  67.     steerDir := 0
  68. }
  69. Right:: {
  70.     global
  71.     steerDir := 1
  72.     KeyWait "Right"
  73.     steerDir := 0
  74. }
  75.  
  76. info := ""
  77. debugInfo(name, value) {
  78.     global
  79.     info .= name ": " value "`n"
  80. }
  81.  
  82. showInfo() {
  83.     tooltip info, 50, 10
  84. }
  85.  
  86. resetInfo() {
  87.     global
  88.     info := ""
  89. }
  90.  
  91. getAks() {
  92.     global
  93.     akPair := []
  94.     loop ak.length {
  95.         if (ak[A_Index])
  96.             akPair.push(A_Index)
  97.     }
  98.     return akPair
  99. }
  100.  
  101. press(key) {
  102.     Send "{" key " down}"
  103.     sleep 1
  104.     Send "{" key " up}"
  105.     sleep 0
  106. }
  107.  
  108. setAk(key) {
  109.     global
  110.     tooltip "setAk: " key, 300, 300, 2
  111.     SetTimer () => ToolTip(,,,2), -500
  112.  
  113.     lastAk := key
  114.     press(keys[key])
  115. }
  116.  
  117. steerDir := 0
  118. Ldown := 0
  119. Rdown := 0
  120. turnL := 0
  121. turnR := 0
  122. sendL := 0
  123. sendR := 0
  124. updateKeys() {
  125.     global
  126.    
  127.     resetInfo()
  128.     akCount := 0
  129.     loop keys.length {
  130.         state := GetKeyState(keys[A_Index], "P")
  131.         ak[A_Index] := state
  132.         akCount += state
  133.         debugInfo("ak" A_index, state)
  134.     }
  135.    
  136.     debugInfo("lastAk", lastAk)
  137.     debugInfo("akCount", akCount)
  138.     debugInfo("left", getKeyState("Left", "P"))
  139.     debugInfo("right", getKeyState("Right", "P"))
  140.     debugInfo("lastAk", lastAk)
  141.    
  142.     aks := getAks()
  143.     if getKeyState("Left", "P") {
  144.     if !Ldown
  145.         Ldown := 1
  146.     } else if Ldown
  147.         Ldown := 0
  148.  
  149.     if getKeyState("Right", "P") {
  150.     if !Rdown
  151.         Rdown := 1
  152.     } else if Rdown
  153.         Rdown := 0
  154.    
  155.     debugInfo("Ldown", Ldown)
  156.     debugInfo("Rdown", Rdown)
  157.     debugInfo("steerDir", steerDir)    
  158.    
  159.     if akCount == 2 {
  160.         if (steerDir == -1) {
  161.             if !turnL
  162.                 turnL := 2
  163.             if Ldown
  164.                 setAk(aks[2])
  165.             else
  166.                 setAk(aks[1])
  167.         }
  168.     } else {
  169.         turnL := Ldown
  170.         turnR := Rdown
  171.     }
  172.  
  173.     debugInfo("turnL", turnL)
  174.     debugInfo("turnR", turnR)
  175.    
  176.     if (turnL > 0) {
  177.         if (!sendL) {
  178.             Send "{Left down}"
  179.             sendL := 1
  180.         }
  181.     } else {
  182.         if (sendL) {
  183.             Send "{Left up}"
  184.             sendL := 0
  185.         }
  186.     }
  187.  
  188.     if (turnR > 0) {
  189.         if (!sendR) {
  190.             Send "{Right down}"
  191.             sendR := 1
  192.         }
  193.     } else {
  194.         if (sendR) {
  195.             Send "{Right up}"
  196.             sendR := 0
  197.         }
  198.     }
  199.    
  200.     debugInfo("sendL", sendL)
  201.     debugInfo("sendR", sendR)
  202.    
  203.     showInfo()
  204. }
  205.  
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement