Change run key to ctrl and some other messy stuff to make that work,,
This commit is contained in:
@@ -76,6 +76,16 @@ export type KeyCode =
|
||||
| "F11"
|
||||
| "F12";
|
||||
|
||||
// the keys the game keeps in fullscreen, see "fullscreenchange". not every key: with all of them locked, chromium
|
||||
// can keep alt+tab and the windows key from the os too
|
||||
const FULLSCREEN_LOCKED_KEYS = ["Escape", "KeyW"];
|
||||
|
||||
// chromium's keyboard lock api, typescript's dom types don't have it yet
|
||||
interface KeyboardLock {
|
||||
lock(codes?: string[]): Promise<void>;
|
||||
unlock(): void;
|
||||
}
|
||||
|
||||
export class InputManager {
|
||||
static keys_down = new Set<string>();
|
||||
static keys_pressed = new Set<string>();
|
||||
@@ -205,6 +215,18 @@ export class InputManager {
|
||||
this.pointer_lock_waiting = false;
|
||||
});
|
||||
|
||||
// in fullscreen, chromium's keyboard lock gives the game escape (holding it still leaves fullscreen) and ctrl+w,
|
||||
// instead of the browser leaving fullscreen or closing the tab. other browsers don't have it and work as before
|
||||
document.addEventListener("fullscreenchange", () => {
|
||||
const keyboard = (navigator as Navigator & { keyboard?: KeyboardLock }).keyboard;
|
||||
if (!keyboard?.lock) return;
|
||||
if (document.fullscreenElement) {
|
||||
keyboard.lock(FULLSCREEN_LOCKED_KEYS).catch(() => {});
|
||||
} else {
|
||||
keyboard.unlock();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("pointerlockerror", () => {
|
||||
this.pointer_lock_waiting = false;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user