Skip to content

Instantly share code, notes, and snippets.

@atward
Last active May 29, 2017 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atward/063b1c1fceb62b3de9a5214d4a19f36a to your computer and use it in GitHub Desktop.
Save atward/063b1c1fceb62b3de9a5214d4a19f36a to your computer and use it in GitHub Desktop.
Oxygen Not Included: Priority shortcut keys
; Oxygen Not included fast priority keybindings.
;
; Instructions:
; - start ahk script
; - start game
; - hit q, wait bit to scan UI
; - use numbers as priorities
;
; Original credits:
; https://www.reddit.com/r/Oxygennotincluded/comments/5vw1us/tired_of_clicking_a_priority_use_autohotkey_to/de8fgnt/
; I use a 60% keyboard with capslock as FN, so modified to use q
; Had some issues with 2K display so hardcoded max scan height
; see getcoords() and alt+F1 if having issues
;
#InstallMouseHook
#InstallKeybdHook
;sendmode play
_pbuttons := _pmode := 0
; set true to reverse priority order
invert := false
; set 'charset' to any 9 key array for each priority
qwerty := ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
azerty := ["&", "é", """", "'", "(", "§", "è", "!", "ç"]
custom := ["q", "w", "e", "r", "t", "y", "u", "i", "o"]
charset = qwerty
return
#ifwinactive Oxygen Not Included ahk_class UnityWndClass
q::
_pmode := !_pmode
send % (_pmode) ? "{p}" : "{rbutton}"
; delay is needed bc of the superfluous fade effect
if !_pbuttons {
tooltip waiting for ui...
settimer pbuttons, -2000
}
;keywait q
return
#if winactive("Oxygen Not Included ahk_class UnityWndClass") && _pmode
rbutton::
send % !(_pmode := 0) ? "{rbutton down}" :
keywait rbutton
send {rbutton up}
return
; debug only
!f1::
o := ""
for k, v in _pbuttons
o .= k ": " v["x"] ", " v["y"] "`n"
msgbox % o
return
; bind this sub to each key in charset
setpriority:
if !_pmode {
send {%a_thishotkey%}
return
}
if !_pbuttons
return
mousegetpos, _x, _y
blockinput mousemove
;click % _pbuttons[a_thishotkey]["x"] ", " _pbuttons[a_thishotkey]["y"]
MouseClick Left, _pbuttons[a_thishotkey]["x"], _pbuttons[a_thishotkey]["y"], 1, 0
mousemove, _x, _y, 0
blockinput mousemoveoff
return
pbuttons:
_pbuttons := remap(%charset%, getcoords(invert))
return
nottip:
tooltip
return
remap(keys, coords) {
obj := {}
for i, v in keys {
obj[v] := coords[i]
hotkey ifwinactive, Oxygen Not Included ahk_class UnityWndClass
try
hotkey % getkeyname(v), setpriority
catch
msgbox
(
" %v% " is not a valid key.
`nFor best compatibility, assign it as a virtual key and/or scan code.
https://autohotkey.com/docs/KeyList.htm#SpecialKeys
)
}
return obj
}
getcoords(i) {
obj := {}
wingetpos,,, w, h, a
; in/active button colors: 0x3E4357, 0x808AB2
; scan bottom right corner ui, find top left corner of button row/priority 5
; atward, new colours? 0x3f4253, 0x8389b2
; display start: 2230 1400
; x1 := ceil(w * .8), y1 := ceil(h * .95)
; above on 2k result in hitting DIG or other keys
x1 := 2230, y1 := 1400
pixelsearch px1, py, x1, y1, w, h, 0x3e4357,, fast rgb
pixelsearch px2,, x1, y1, w, h, 0x808ab2,, fast rgb
xdelta := ceil((px2 - px1) / 4)
loop 9
obj[(i ? (9 - (a_index - 1)) : a_index)] := {"x": (px1 + (xdelta * (a_index - 1))), "y": py}
tooltip priority keys set!
settimer nottip, -3000
return obj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment