Skip to content

Commit

Permalink
Fix hotkeys menu crash + New/Fixed keybind support (#6565)
Browse files Browse the repository at this point in the history
# About the pull request

This PR fixes a crash when using the search by key feature in the
Keybinds window when the panel is filtered, and maps a bunch of keys to
byond bindings.

Of note, there are three locations remapping keys:

https://github.com/cmss13-devs/cmss13/blob/master/tgui/packages/tgui/interfaces/KeyBinds.jsx#L14-L26

https://github.com/cmss13-devs/cmss13/blob/master/tgui/packages/common/keys.ts#L20-L39

https://github.com/cmss13-devs/cmss13/blob/master/code/_globalvars/lists/client.dm#L7-L23

Since the first two are as they are on TG, I opted to update the third
one which seems to be unique to our codebase

# Explain why it's good for the game

Fixes various keybinds (namely keypad stuff), adds a bunch of new
keybinds (media keys), and fixes a tgui crash.

Fixes: 

![image](https://github.com/cmss13-devs/cmss13/assets/76988376/8c4dd0ba-7185-4f45-a089-c8ee6edf06b7)

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>


![hotkeys](https://github.com/cmss13-devs/cmss13/assets/76988376/404483f5-9ea3-43e3-8c35-26e6e73d99fc)

</details>


# Changelog
:cl: Drathek
fix: Fixed a crash in the Hotkey menu when searching by key when
filtered
fix: Fixed/Added support for various keys (e.g. keypad and media keys)
/:cl:

---------

Co-authored-by: harryob <[email protected]>
  • Loading branch information
Drulikar and harryob authored Jun 27, 2024
1 parent efb0858 commit 6dfc611
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
26 changes: 24 additions & 2 deletions code/_globalvars/lists/client.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,42 @@ GLOBAL_LIST_EMPTY(keybindings_by_name)
// This is a mapping from JS keys to Byond - ref: https://keycode.info/
GLOBAL_LIST_INIT(_kbMap, list(
"UP" = "North",
"ARROWUP" = "North",
"RIGHT" = "East",
"ARROWRIGHT" = "East",
"DOWN" = "South",
"ARROWDOWN" = "South",
"LEFT" = "West",
"ARROWLEFT" = "West",
"INSERT" = "Insert",
"HOME" = "Northwest",
"PAGEUP" = "Northeast",
"DEL" = "Delete",
"DEL" = "Delete", // Unlikely this is correct now
"DELETE" = "Delete",
"END" = "Southwest",
"PAGEDOWN" = "Southeast",
"SPACEBAR" = "Space",
"ENTER" = "Return",
"ALT" = "Alt",
"SHIFT" = "Shift",
"CONTROL" = "Ctrl"
"CONTROL" = "Ctrl",
"MULTIPLY" = "Multiply",
"DIVIDE" = "Divide",
"SUBTRACT" = "Subtract",
"ADD" = "Add",
"DECIMAL" = "Decimal",
"CLEAR" = "Center",
"PAUSE" = "Pause",
"CONTEXTMENU" = "Apps",
"NUMLOCK" = "Numlock",
"SCROLLLOCK" = "Scroll",
"MEDIANEXTTRACK" = "MediaNext",
"MEDIAPLAYPAUSE" = "MediaPlayPause",
"MEDIASTOP" = "MediaStop",
"MEDIAPREVIOUSTRACK" = "MediaPrev",
"VOLUMEMUTE" = "VolumeMute",
"VOLUMEUP" = "VolumeUp",
"VOLUMEDOWN" = "VolumeDown",
))

///List of ckeys that have seen a blurb of a given key.
Expand Down
14 changes: 10 additions & 4 deletions tgui/packages/tgui/interfaces/KeyBinds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ export const KeyBinds = (props) => {
if (!targetEntry) {
return;
}
// If a keybind was found, scroll to the first match.
document
.getElementById(targetEntry[0])
.scrollIntoView();
// If a keybind was found, scroll to the first match currently rendered.
for (let i = 0; i < targetEntry.length; i++) {
const element = document.getElementById(
targetEntry[i],
);
if (element) {
element.scrollIntoView();
break;
}
}
}}
/>
</Flex.Item>
Expand Down

0 comments on commit 6dfc611

Please sign in to comment.