Last active
July 24, 2025 20:33
-
-
Save pongo/fb7dcfad0f6531ff26346721e75869a1 to your computer and use it in GitHub Desktop.
Utils for tinykeys https://github.com/jamiebuilds/tinykeys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createKeybindingsHandler } from "tinykeys"; | |
// code from https://github.com/jaywcjlove/hotkeys-js/blob/master/src/index.js | |
function isInput(event: KeyboardEvent) { | |
const target = event.target as HTMLInputElement; | |
const { tagName } = target; | |
const isInput = | |
tagName === "INPUT" && | |
!["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes( | |
target.type, | |
); | |
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select> | |
if ( | |
target.isContentEditable || | |
((isInput || tagName === "TEXTAREA" || tagName === "SELECT") && !target.readOnly) | |
) { | |
return true; | |
} | |
return false; | |
} | |
function notInput(listener: (event: KeyboardEvent) => void) { | |
return (event: KeyboardEvent) => { | |
if (!isInput(event)) { | |
listener(event); | |
} | |
}; | |
} | |
const handler = createKeybindingsHandler({ | |
KeyQ: notInput((event: KeyboardEvent) => { | |
event.preventDefault(); | |
event.stopPropagation(); | |
console.log("q"); | |
}), | |
KeyA: notInput((event: KeyboardEvent) => { | |
event.preventDefault(); | |
event.stopPropagation(); | |
console.log("a"); | |
}), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/tinykeys/package.json b/node_modules/tinykeys/package.json | |
index bbda4b2..38fc5a5 100644 | |
--- a/node_modules/tinykeys/package.json | |
+++ b/node_modules/tinykeys/package.json | |
@@ -16,7 +16,8 @@ | |
"exports": { | |
".": { | |
"import": "./dist/tinykeys.module.js", | |
- "require": "./dist/tinykeys.js" | |
+ "require": "./dist/tinykeys.js", | |
+ "types": "./dist/tinykeys.d.ts" | |
} | |
}, | |
"keywords": [ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment