Files
Bubberstation/code/modules/keybindings/bindings_client.dm
Couls 26a61a489c ports TGMCs click hack for non-hotkey players ports classic keybinds from TGMC (#47670)
About The Pull Request

Ports tgstation/TerraGov-Marine-Corps#2977, overrides click proc to return focus back to chat bar using winsets also ports tgstation/TerraGov-Marine-Corps#1904 which has two sets of defaults for hotkey and classic mode
fixes #47672 fixes #47659

much credit to @Rohesie and the TGMC team for a bunch of these improvements
Why It's Good For The Game

lets the non-hotkey players walk and talk again
Changelog

cl
add: Custom keybinds will now check what style (classic / hotkey) you prefer when resetting if you use classic mode make sure to reset your keybinds to default!
add: multiple keybind support
tweak: non-hotkey mode keeps focus on chat
fix: pressing 4 as cyborg now properly cycles
fix: AI location hotkeys now work again
/cl
2019-11-14 09:22:33 +13:00

100 lines
4.0 KiB
Plaintext

// Clients aren't datums so we have to define these procs indpendently.
// These verbs are called for all key press and release events
/client/verb/keyDown(_key as text)
set instant = TRUE
set hidden = TRUE
client_keysend_amount += 1
var/cache = client_keysend_amount
if(keysend_tripped && next_keysend_trip_reset <= world.time)
keysend_tripped = FALSE
if(next_keysend_reset <= world.time)
client_keysend_amount = 0
next_keysend_reset = world.time + (1 SECONDS)
//The "tripped" system is to confirm that flooding is still happening after one spike
//not entirely sure how byond commands interact in relation to lag
//don't want to kick people if a lag spike results in a huge flood of commands being sent
if(cache >= MAX_KEYPRESS_AUTOKICK)
if(!keysend_tripped)
keysend_tripped = TRUE
next_keysend_trip_reset = world.time + (2 SECONDS)
else
log_admin("Client [ckey] was just autokicked for flooding keysends; likely abuse but potentially lagspike.")
message_admins("Client [ckey] was just autokicked for flooding keysends; likely abuse but potentially lagspike.")
QDEL_IN(src, 1)
return
///Check if the key is short enough to even be a real key
if(LAZYLEN(_key) > MAX_KEYPRESS_COMMANDLENGTH)
to_chat(src, "<span class='userdanger'>Invalid KeyDown detected! You have been disconnected from the server automatically.</span>")
log_admin("Client [ckey] just attempted to send an invalid keypress. Keymessage was over [MAX_KEYPRESS_COMMANDLENGTH] characters, autokicking due to likely abuse.")
message_admins("Client [ckey] just attempted to send an invalid keypress. Keymessage was over [MAX_KEYPRESS_COMMANDLENGTH] characters, autokicking due to likely abuse.")
QDEL_IN(src, 1)
return
//Focus Chat failsafe. Overrides movement checks to prevent WASD.
if(!prefs.hotkeys && length(_key) == 1 && _key != "Alt" && _key != "Ctrl" && _key != "Shift")
winset(src, null, "input.focus=true ; input.text=[url_encode(_key)]")
return
//offset by 1 because the buffer address is 0 indexed because the math was simpler
keys_held[current_key_address + 1] = _key
//the time a key was pressed isn't actually used anywhere (as of 2019-9-10) but this allows easier access usage/checking
keys_held[_key] = world.time
current_key_address = ((current_key_address + 1) % HELD_KEY_BUFFER_LENGTH)
var/movement = movement_keys[_key]
if(!(next_move_dir_sub & movement) && !keys_held["Ctrl"])
next_move_dir_add |= movement
// Client-level keybindings are ones anyone should be able to do at any time
// Things like taking screenshots, hitting tab, and adminhelps.
var/AltMod = keys_held["Alt"] ? "Alt" : ""
var/CtrlMod = keys_held["Ctrl"] ? "Ctrl" : ""
var/ShiftMod = keys_held["Shift"] ? "Shift" : ""
var/full_key
switch(_key)
if("Alt", "Ctrl", "Shift")
full_key = "[AltMod][CtrlMod][ShiftMod]"
else
full_key = "[AltMod][CtrlMod][ShiftMod][_key]"
var/keycount = 0
for(var/kb_name in prefs.key_bindings[full_key])
keycount++
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.down(src) && keycount >= MAX_COMMANDS_PER_KEY)
break
holder?.key_down(_key, src)
mob.focus?.key_down(_key, src)
/client/verb/keyUp(_key as text)
set instant = TRUE
set hidden = TRUE
//Can't just do a remove because it would alter the length of the rolling buffer, instead search for the key then null it out if it exists
for(var/i in 1 to HELD_KEY_BUFFER_LENGTH)
if(keys_held[i] == _key)
keys_held[i] = null
break
var/movement = movement_keys[_key]
if(!(next_move_dir_add & movement))
next_move_dir_sub |= movement
// We don't do full key for release, because for mod keys you
// can hold different keys and releasing any should be handled by the key binding specifically
for (var/kb_name in prefs.key_bindings[_key])
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.up(src))
break
holder?.key_up(_key, src)
mob.focus?.key_up(_key, src)
// Called every game tick
/client/keyLoop()
holder?.keyLoop(src)
mob.focus?.keyLoop(src)