Merge pull request #8 from colbychittenden/main

Added keyboard toggling
This commit is contained in:
FlamedDogo99 2024-06-02 17:12:55 -05:00 committed by GitHub
commit 41f6a7d88a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ function isMobile() {
if(!isMobile()) { if(!isMobile()) {
alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!"); alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!");
} }
window.keyboardEnabled = false;
window.crouchLock = false; window.crouchLock = false;
window.sprintLock = false; window.sprintLock = false;
// Used for changing touchmove events to mousemove events // Used for changing touchmove events to mousemove events
@ -105,7 +106,7 @@ document.exitFullscreen = function() {
} }
// FILE UPLOADING // FILE UPLOADING
// Safari doesn't recognize the element.click() used to display the file uplaoder as an action performed by the user, so it ignores it. // Safari doesn't recognize the element.click() used to display the file uploader as an action performed by the user, so it ignores it.
// This hijacks the element.createElement() function to add the file upload to the DOM, so the user can manually press the button again. // This hijacks the element.createElement() function to add the file upload to the DOM, so the user can manually press the button again.
var oldCreate = document.createElement; var oldCreate = document.createElement;
document.createElement = function(type, ignore) { document.createElement = function(type, ignore) {
@ -173,6 +174,17 @@ function createTouchButton(buttonClass, buttonDisplay, elementName) {
return touchButton; return touchButton;
} }
function toggleKeyboard() {
const keyboardInput = document.getElementById('hiddenInput');
if (window.keyboardEnabled) {
window.keyboardEnabled = false;
keyboardInput.blur();
} else {
window.keyboardEnabled = true;
keyboardInput.select();
}
}
waitForElm('canvas').then(() => {insertCanvasElements()}); waitForElm('canvas').then(() => {insertCanvasElements()});
function insertCanvasElements() { function insertCanvasElements() {
// Translates touchmove events to mousemove events when inGame, and touchmove events to wheele events when inMenu // Translates touchmove events to mousemove events when inGame, and touchmove events to wheele events when inMenu
@ -311,15 +323,13 @@ function insertCanvasElements() {
document.body.appendChild(exitButton); document.body.appendChild(exitButton);
// input for keyboard button // input for keyboard button
let hiddenInput = document.createElement('input', true); let hiddenInput = document.createElement('input', true);
hiddenInput.type = "text"
hiddenInput.id = "hiddenInput" hiddenInput.id = "hiddenInput"
// hiding behind button for opacity issues hiddenInput.style.cssText = "opacity:0;z-index:-99999";
hiddenInput.style.cssText = "z-index: -999; top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;";
document.body.appendChild(hiddenInput); document.body.appendChild(hiddenInput);
let keyboardButton = createTouchButton("keyboardButton", "inMenu"); let keyboardButton = createTouchButton("keyboardButton", "inMenu");
keyboardButton.style.cssText = "top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;" keyboardButton.style.cssText = "top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;"
keyboardButton.addEventListener("touchstart", function(e){e.preventDefault();hiddenInput.blur()}, false); keyboardButton.addEventListener("touchstart", function(e){e.preventDefault();hiddenInput.blur()}, false);
keyboardButton.addEventListener("touchend", function(e){hiddenInput.select()}, false); keyboardButton.addEventListener("touchend", function(e){e.preventDefault();toggleKeyboard()}, false);
document.body.appendChild(keyboardButton); document.body.appendChild(keyboardButton);
let placeButton = createTouchButton("placeButton", "inGame"); let placeButton = createTouchButton("placeButton", "inGame");
placeButton.style.cssText = "right:0vh;bottom:20vh;" placeButton.style.cssText = "right:0vh;bottom:20vh;"