List of keyboard shortcuts + custom shortcuts + gamepad support #612
-
|
When using Is it possible to add custom keyboard shortcuts? Why? Because the tiny 8BitDo Zero 2 can be used as a keyboard, but it only sends letters, not arrow keys. Is it possible to control the presentation using a gamepad? (Yes, I searched the forums, but found nothing related to these questions.) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Assuming you are using a
Existing shortcuts cannot customize, but it's possible to add JavaScript to Markdown to simulate pressing a shortcut key when a specific key is pressed. Please note that you have to add a # Slide 1
---
# Slide 2
...
<script>
// [Example] WASD navigation: Put the script into the last of Markdown once
document.addEventListener('keydown', (e) => {
if (e.key === 'd' || e.key === 's') {
document.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight" })); // Send "ArrowRight" for next slide
} else if (e.key === 'a' || e.key === 'w') {
document.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft" })); // Send "ArrowLeft" for previous slide
}
})
</script>And also you can write a script for supporting the gamepad through Gamepad API. |
Beta Was this translation helpful? Give feedback.
-
|
More shortcuts (but only in the presenter window):
For completeness sake, and for future reference, I'm adding the full code I've used. I had to call // Adding support for 8BitDo Zero 2 keyboard mode.
document.addEventListener("keydown", function(ev) {
const keymap = {
e: { key: "ArrowLeft" , code: "ArrowLeft" , shiftKey: false }, // 8BitDo Zero 2: LEFT
i: { key: "ArrowLeft" , code: "ArrowLeft" , shiftKey: false }, // 8BitDo Zero 2: Y button (left)
f: { key: "ArrowRight", code: "ArrowRight", shiftKey: false }, // 8BitDo Zero 2: RIGHT
g: { key: "ArrowRight", code: "ArrowRight", shiftKey: false }, // 8BitDo Zero 2: A button (right)
c: { key: "ArrowLeft" , code: "ArrowLeft" , shiftKey: true }, // 8BitDo Zero 2: UP
h: { key: "ArrowLeft" , code: "ArrowLeft" , shiftKey: true }, // 8BitDo Zero 2: X button (top)
d: { key: "ArrowRight", code: "ArrowRight", shiftKey: true }, // 8BitDo Zero 2: DOWN
j: { key: "ArrowRight", code: "ArrowRight", shiftKey: true }, // 8BitDo Zero 2: B button (bottom)
k: { key: "-" , code: "Minus", shiftKey: false }, // 8BitDo Zero 2: L shoulder button
m: { key: "+" , code: "Equal", shiftKey: true }, // 8BitDo Zero 2: R shoulder button
};
const options = keymap[ev.key];
if (options) {
ev.stopPropagation();
document.dispatchEvent(new KeyboardEvent("keydown", {
...options,
repeat: ev.repeat,
}));
// I don't need to bother with "keyup" events because they are not used by Marp's Bespoke template.
}
}, { capture: true });For anyone wanting to do something similar, I recommend using these two tools (that I wrote myself) to figure out the keys and properties: If anyone wants to add gamepad support, please be my guest and share your code here. Or, even better, consider creating a PR. |
Beta Was this translation helpful? Give feedback.
Assuming you are using a
bespoketemplate with Marp CLI, the following keyboard shortcuts are available:Existing shortcuts cannot customize, but it's possible to add JavaScript to Markdown to simulate pressing a shortcut key when a specific…