mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 14:56:01 +00:00
Merge pull request #3043 from matthewturk/keyboard_lock
Allow keyboard lock
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user