Display key press on web page
This is a simple web component, you can use it just like normal html element.
- display key press
- merge repeat key press and show repeat count
- combine modifier key and other key
npm install key-display
or just copy the key-display.js
file
Please check the example
<script type="module">
import defineKeyDisplay from "../key-display.js";
defineKeyDisplay({
maxKeys: 3,
timeout: 100000,
upperLetter: false,
mergeModifierKey: false,
mergeRepeatKey: true,
showRepeatCount: true,
});
window.onload = () => {
const keyDisplay = document.createElement("key-display");
document.body.appendChild(keyDisplay);
};
</script>
<script setup>
import defineKeyDisplay from 'key-display';
defineKeyDisplay({
maxKeys: 3,
timeout: 100000,
upperLetter: false,
mergeModifierKey: false,
mergeRepeatKey: true,
showRepeatCount: true,
});
</script>
and you need set compilerOptions.isCustomElement
in vite.config.js
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => ["key-display"].includes(tag),
},
},
}),
],
})
maxKeys
: max number of displayed keystimeout
: time to disappearupperLetter
: convert letter to uppercasemergeModifierKey
: for example: Shift + QmergeRepeatKey
: merge last repeat key pressshowRepeatCount
: show repeat count