Improve chat input
This commit is contained in:
+20
-1
@@ -53,6 +53,8 @@ export type KeyCode =
|
||||
| "ShiftRight"
|
||||
| "ControlLeft"
|
||||
| "ControlRight"
|
||||
| "MetaLeft"
|
||||
| "MetaRight"
|
||||
| "AltLeft"
|
||||
| "AltRight"
|
||||
| "Home"
|
||||
@@ -92,6 +94,8 @@ export class InputManager {
|
||||
|
||||
// in the order they were typed. a list, since the same letter can be typed twice in one frame
|
||||
static typed_characters: string[] = [];
|
||||
// letters pressed with ctrl (cmd on macs) held, like "a" for select all
|
||||
static shortcuts: string[] = [];
|
||||
|
||||
static pointer_lock_flag = false;
|
||||
static mouse_grab_timer = 0;
|
||||
@@ -110,7 +114,11 @@ export class InputManager {
|
||||
}
|
||||
this.keys_down.add(e.code);
|
||||
if (e.key.length === 1) {
|
||||
this.typed_characters.push(e.key);
|
||||
if (this.#is_shortcut(e)) {
|
||||
this.shortcuts.push(e.key.toLowerCase());
|
||||
} else {
|
||||
this.typed_characters.push(e.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -222,6 +230,16 @@ export class InputManager {
|
||||
this.mouse_buttons_consumed.add(button);
|
||||
}
|
||||
|
||||
// ctrl (cmd on macs) held for a shortcut. altgr types characters like @ and comes as ctrl+alt on windows, so it
|
||||
// isn't one. getModifierState("AltGraph") isn't used, some linux layouts report it along with plain ctrl
|
||||
static #is_shortcut(e: KeyboardEvent) {
|
||||
return e.metaKey || (e.ctrlKey && !e.altKey);
|
||||
}
|
||||
|
||||
static is_shortcut_pressed(letter: string): boolean {
|
||||
return this.shortcuts.includes(letter);
|
||||
}
|
||||
|
||||
static get_typed_characters(): string[] {
|
||||
const chars = this.typed_characters;
|
||||
this.typed_characters = [];
|
||||
@@ -237,6 +255,7 @@ export class InputManager {
|
||||
this.mouse_delta_y = 0;
|
||||
this.wheel_delta = 0;
|
||||
this.typed_characters = [];
|
||||
this.shortcuts = [];
|
||||
this.mouse_buttons_consumed.clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user