feat(nds): improve key input system
This commit is contained in:
@@ -221,7 +221,7 @@ export const useButtonNavigation = <T extends Record<string, Rect>>({
|
||||
}
|
||||
});
|
||||
|
||||
useKeyDown((key) => {
|
||||
useKeyDown(({ key }) => {
|
||||
if (blockInteractions.value) return;
|
||||
|
||||
const currentButton = selectedButton.value as Entry;
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
export type KeyDownCallback = (key: string) => void;
|
||||
import { mapKeyToNDS } from "~/utils/input";
|
||||
|
||||
export type KeyDownCallback = (params: {
|
||||
key: string;
|
||||
ndsButton: string | null;
|
||||
repeated: boolean;
|
||||
}) => void;
|
||||
|
||||
export const useKeyDown = (callback: KeyDownCallback) => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
callback(event.key);
|
||||
const ndsButton = mapKeyToNDS(event.key);
|
||||
callback({
|
||||
key: ndsButton ? `NDS_${ndsButton}` : event.key,
|
||||
ndsButton,
|
||||
repeated: event.repeat,
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
export type KeyUpCallback = (key: string) => void;
|
||||
import { mapKeyToNDS } from "~/utils/input";
|
||||
|
||||
export type KeyUpCallback = (params: {
|
||||
key: string;
|
||||
ndsButton: string | null;
|
||||
}) => void;
|
||||
|
||||
export const useKeyUp = (callback: KeyUpCallback) => {
|
||||
const handleKeyUp = (event: KeyboardEvent) => {
|
||||
callback(event.key);
|
||||
const ndsButton = mapKeyToNDS(event.key);
|
||||
callback({
|
||||
key: ndsButton ? `NDS_${ndsButton}` : event.key,
|
||||
ndsButton,
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user