Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; TODO: lock steerDir while holding 2 action keys
- #Requires AutoHotkey v2.0
- #SingleInstance
- SetKeyDelay 0, 0
- A_HotkeyInterval := 0
- SendMode "input"
- CoordMode "tooltip", "screen"
- !X::ExitApp
- !R::Reload
- #UseHook 1
- keys := ["1", "2", "3", "4", "5"]
- ak := [0,0,0,0,0]
- lastAk := 0
- i:: {
- global
- showInfo()
- }
- *1:: {
- global
- setAk(1)
- KeyWait "1"
- setAk(5)
- lastAk := 0
- }
- *2:: {
- global
- setAk(2)
- KeyWait "2"
- setAk(5)
- lastAk := 0
- }
- *3:: {
- global
- setAk(3)
- KeyWait "3"
- setAk(5)
- lastAk := 0
- }
- *4:: {
- global
- setAk(4)
- KeyWait "4"
- setAk(5)
- lastAk := 0
- }
- *5:: {
- global
- setAk(5)
- KeyWait "5"
- setAk(5)
- lastAk := 0
- }
- SetTimer(updateKeys, 100)
- Left:: {
- global
- steerDir := -1
- KeyWait "Left"
- steerDir := 0
- }
- Right:: {
- global
- steerDir := 1
- KeyWait "Right"
- steerDir := 0
- }
- info := ""
- debugInfo(name, value) {
- global
- info .= name ": " value "`n"
- }
- showInfo() {
- tooltip info, 50, 10
- }
- resetInfo() {
- global
- info := ""
- }
- getAks() {
- global
- akPair := []
- loop ak.length {
- if (ak[A_Index])
- akPair.push(A_Index)
- }
- return akPair
- }
- press(key) {
- Send "{" key " down}"
- sleep 1
- Send "{" key " up}"
- sleep 0
- }
- setAk(key) {
- global
- tooltip "setAk: " key, 300, 300, 2
- SetTimer () => ToolTip(,,,2), -500
- lastAk := key
- press(keys[key])
- }
- steerDir := 0
- Ldown := 0
- Rdown := 0
- turnL := 0
- turnR := 0
- sendL := 0
- sendR := 0
- updateKeys() {
- global
- resetInfo()
- akCount := 0
- loop keys.length {
- state := GetKeyState(keys[A_Index], "P")
- ak[A_Index] := state
- akCount += state
- debugInfo("ak" A_index, state)
- }
- debugInfo("lastAk", lastAk)
- debugInfo("akCount", akCount)
- debugInfo("left", getKeyState("Left", "P"))
- debugInfo("right", getKeyState("Right", "P"))
- debugInfo("lastAk", lastAk)
- aks := getAks()
- if getKeyState("Left", "P") {
- if !Ldown
- Ldown := 1
- } else if Ldown
- Ldown := 0
- if getKeyState("Right", "P") {
- if !Rdown
- Rdown := 1
- } else if Rdown
- Rdown := 0
- debugInfo("Ldown", Ldown)
- debugInfo("Rdown", Rdown)
- debugInfo("steerDir", steerDir)
- if akCount == 2 {
- if (steerDir == -1) {
- if !turnL
- turnL := 2
- if Ldown
- setAk(aks[2])
- else
- setAk(aks[1])
- }
- } else {
- turnL := Ldown
- turnR := Rdown
- }
- debugInfo("turnL", turnL)
- debugInfo("turnR", turnR)
- if (turnL > 0) {
- if (!sendL) {
- Send "{Left down}"
- sendL := 1
- }
- } else {
- if (sendL) {
- Send "{Left up}"
- sendL := 0
- }
- }
- if (turnR > 0) {
- if (!sendR) {
- Send "{Right down}"
- sendR := 1
- }
- } else {
- if (sendR) {
- Send "{Right up}"
- sendR := 0
- }
- }
- debugInfo("sendL", sendL)
- debugInfo("sendR", sendR)
- showInfo()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement