mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-18 13:43:27 +00:00
* Fixes Using 'ESC' Key To Unbind Keybindings + Adds Function to Check It Elsewhere (#83710)
## About The Pull Request
Consequence of #80335 (d3554b3902)

Likely some weird IE shit, we get "Esc" instead of "Escape".
I added it as a function so this is a bit hardier to potentially
breaking so it doesn't go haywire silently again when we migrate to
Webview2. It's also likely that a weird combo of OS and IE and BYOND
Version and whatever will spit out "Esc" instead of "Escape", so let's
just have a helper function to access both so we don't have to worry
about it any more.
✅: Works on my machine
## Why It's Good For The Game
Players should be allowed to unbind whatever keys they want, regressions
are bad. New helper function that can check both cases (since we're
unsure of why either case pops up and it's unlikely that we have control
over it) was implemented in every spot where we were checking
`KEY.Escape` in this PR as well.
## Changelog
🆑
fix: Using the 'ESC' key on your keyboard to unbind a key in the
keybindings preferences menu should now work as expected. This should
also be fixed for people in a variety of other spots too.
/🆑
My javascript is a bit bad let me know if I'm doing something wack
* Fixes Using 'ESC' Key To Unbind Keybindings + Adds Function to Check It Elsewhere
---------
Co-authored-by: san7890 <the@san7890.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
/**
|
|
* ### Key codes.
|
|
* event.keyCode is deprecated, use this reference instead.
|
|
*
|
|
* Handles modifier keys (Shift, Alt, Control) and arrow keys.
|
|
*
|
|
* For alphabetical keys, use the actual character (e.g. 'a') instead of the key code.
|
|
* Don't access Esc or Escape directly, use isEscape() instead
|
|
*
|
|
* Something isn't here that you want? Just add it:
|
|
* @url https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
|
|
* @usage
|
|
* ```ts
|
|
* import { KEY } from 'tgui/common/keys';
|
|
*
|
|
* if (event.key === KEY.Enter) {
|
|
* // do something
|
|
* }
|
|
* ```
|
|
*
|
|
*
|
|
*/
|
|
export enum KEY {
|
|
Alt = 'Alt',
|
|
Backspace = 'Backspace',
|
|
Control = 'Control',
|
|
Delete = 'Delete',
|
|
Down = 'ArrowDown',
|
|
End = 'End',
|
|
Enter = 'Enter',
|
|
Esc = 'Esc',
|
|
Escape = 'Escape',
|
|
Home = 'Home',
|
|
Insert = 'Insert',
|
|
Left = 'ArrowLeft',
|
|
PageDown = 'PageDown',
|
|
PageUp = 'PageUp',
|
|
Right = 'ArrowRight',
|
|
Shift = 'Shift',
|
|
Space = ' ',
|
|
Tab = 'Tab',
|
|
Up = 'ArrowUp',
|
|
}
|
|
|
|
/**
|
|
* ### isEscape
|
|
*
|
|
* Checks if the user has hit the 'ESC' key on their keyboard.
|
|
* There's a weirdness in BYOND where this could be either the string
|
|
* 'Escape' or 'Esc' depending on the browser. This function handles
|
|
* both cases.
|
|
*
|
|
* @param key - the key to check, typically from event.key
|
|
* @returns true if key is Escape or Esc, false otherwise
|
|
*/
|
|
export function isEscape(key: string): boolean {
|
|
return key === KEY.Esc || key === KEY.Escape;
|
|
}
|