sandboxels/mods/mobile_keybinds.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2025-11-27 07:56:39 -05:00
(() => {
function runKeybind() {
promptInput("Input the keybind you want to run. (e.g. KeyA, Digit1, Backspace)", (keybind) => {
2025-12-12 03:30:40 -05:00
if (/^[A-Za-z]$/.test(keybind)) keybind = "Key" + keybind.toUpperCase()
if (/^[0-9]$/.test(keybind)) {
setView(Number(keybind))
}
2025-11-27 07:56:39 -05:00
if (keybinds[keybind]) {
keybinds[keybind]();
}
})
}
2025-12-12 03:30:40 -05:00
function loadButton() {
2025-11-27 07:56:39 -05:00
const keybindButton = document.createElement("button")
2025-12-12 03:30:40 -05:00
if (!keybindButton) {
setTimeout(loadButton, 100)
return
}
2025-11-27 07:56:39 -05:00
keybindButton.id = "keybindButton"
2025-12-12 03:30:40 -05:00
keybindButton.title = "Input a keybind"
2025-11-27 07:56:39 -05:00
keybindButton.classList.add("controlButton")
keybindButton.onclick = () => {
runKeybind()
}
keybindButton.textContent = "Keybind"
document.getElementById("pauseButton").before(keybindButton)
}
2025-12-12 03:30:40 -05:00
if (isMobile) {
loadButton()
}
})()