Keyboard Mapping Example
Directions:
- Open the console to see the logged messages.
-
Press the specified keyboard combinations to trigger the corresponding
actions:
- Change the Scope by Pressing any of the following Keys:
- Press 0: Log "0 pressed. Changing scope to default."
- Press 1: Log "1 pressed. Changing scope to scope1."
- Press 2,3,4,5: Log "2 pressed. Changing scope to scope2."
- Default Scope Mappings:
- Ctrl+A: Log "Ctrl+A pressed"
-
Ctrl+S: Log "Ctrl+S pressed (does not activate save mode as the key
overrides the default function)"
- Shift+Enter: Log "Shift+Enter pressed"
- Ctrl+Shift+D: Log "Ctrl+Shift+D pressed"
- Escape: Log "Escape pressed."
- Scope 1 Mappings
- Scope 2 Mappings
-
Modify the keyboard mappings in the code and experiment with your own
combinations and actions.
JavaScript Code:
const keyboardMapper = new KeyboardMapper();
keyboardMapper.mapCombination("ctrl+a", () => {
console.log("Ctrl+A pressed");
});
keyboardMapper.mapCombination("shift+enter", () => {
console.log("Shift+Enter pressed");
});
keyboardMapper.mapCombination("ctrl+shift+d", () => {
console.log("Ctrl+Shift+D pressed");
});
keyboardMapper.mapCombination("escape", () => {
console.log("Escape pressed.");
});
keyboardMapper.mapCombination("0", () => {
console.log("0 pressed. Changing scope to default.");
// Change the scope (optional)
keyboardMapper.setScope("default");
});
keyboardMapper.mapCombination("1", () => {
console.log("1 pressed. Changing scope to scope1.");
// Change the scope (optional)
keyboardMapper.setScope("scope1");
});
keyboardMapper.mapCombination("ctrl+s", () => {
console.log("Ctrl+S");
});
keyboardMapper.mapCombination("2,3,4,5", () => {
console.log("2 pressed. Changing scope to scope2.");
// Change the scope (optional)
keyboardMapper.setScope("scope2");
});
keyboardMapper.mapCombination(
"ctrl+c",
() => {
console.log("Ctrl+C");
},
"scope1"
);
keyboardMapper.mapCombination(
"ctrl+z",
() => {
console.log("Ctrl+Z");
},
"scope2"
);