-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* ### 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters