Merge pull request #3043 from matthewturk/keyboard_lock

Allow keyboard lock
This commit is contained in:
Georges-Antoine Assi
2026-02-28 18:28:27 -05:00
committed by GitHub

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useLocalStorage } from "@vueuse/core";
import { useEventListener, useLocalStorage } from "@vueuse/core";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from "vue";
@@ -41,6 +41,15 @@ const supportedCores = ref<string[]>([]);
const gameRunning = ref(false);
const fullScreenOnPlay = useLocalStorage("emulation.fullScreenOnPlay", true);
declare global {
interface Navigator {
keyboard: {
lock: (keys: string[]) => Promise<void>;
unlock: () => void;
};
}
}
const compatibleStates = computed(
() =>
rom.value?.user_states.filter(
@@ -173,6 +182,18 @@ onMounted(async () => {
emitter?.on("saveSelected", selectSave);
emitter?.on("stateSelected", selectState);
if ("keyboard" in navigator) {
useEventListener(document, "fullscreenchange", () => {
if (document.fullscreenElement) {
navigator.keyboard
.lock(["Escape", "Tab", "AltLeft", "ControlLeft", "MetaLeft"])
.catch(() => {});
} else {
navigator.keyboard.unlock();
}
});
}
// Determine default tab and selection (mutually exclusive)
const compatibleStates = rom.value.user_states.filter(
(s) => !s.emulator || s.emulator === supportedCores.value[0],