From f5e74945ecf6358026113751f778aee726cb7528 Mon Sep 17 00:00:00 2001 From: FlamedDogo99 <96555444+FlamedDogo99@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:26:45 -0600 Subject: [PATCH] Auto detect keyboard issue First attempt: hiddenInput saves the most recent value to window.lastKey If we detect a keydown event with invalid key, keyCode or which, we enable window.keyboardFix, and redispatch the key from window.lastKey The keyboard blocking function now checks for window.keyboardFix --- eaglermobile.user.js | 53 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/eaglermobile.user.js b/eaglermobile.user.js index 936920b..49bbf14 100644 --- a/eaglermobile.user.js +++ b/eaglermobile.user.js @@ -26,6 +26,7 @@ if(!isMobile()) { window.keyboardEnabled = false; window.crouchLock = false; window.sprintLock = false; +window.keyboardFix = false // Used for changing touchmove events to mousemove events var previousTouchX = null; var previousTouchY = null; @@ -41,7 +42,7 @@ Object.defineProperty(EventTarget.prototype, "addEventListener", { value: function (type, fn, ...rest) { if(type == 'keydown') { _addEventListener.call(this, type, function(...args) { - if(!args[0].isValid) { + if(!args[0].isValid && window.keyboardFix) { return; } return fn.apply(this, args); @@ -59,6 +60,36 @@ Event.prototype.preventDefault = function() { this._preventDefault(); } } +function hiddenInputHandler (e) { + let inputData = e.data.charAt(0) + window.lastKey = inputData + hiddenInput.value = " "; // We need a character to detect deleting + if(window.keyboardFix) { + if(e.inputType == 'insertText') { + let inputData = e.data.charAt(0); + let isShift = (inputData.toLowerCase() != inputData); + if(isShift) { + keyEvent("shift", "keydown") + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + keyEvent("shift", "keyup") + } else { + keyEvent(inputData, "keydown"); + keyEvent(inputData, "keyup"); + } + } else if (e.inputType == 'deleteContentForward' || e.inputType == 'deleteContentBackward') { + keyEvent("backspace", "keydown") + keyEvent("backspace", "keyup") + } + } +} +window.addEventListener("keydown", function(e) { + if((e.key == null || e.keyCode == null || e.which = null) && !window.keyboardFix) { + window.keyboardFix = true; + keyEvent(window.lastKey, "keydown") + keyEvent(window.lastKey, "keyup") + } +}, false); // Key and mouse events // Note: the client must have the key, keyCode, and which parameters defined or it will crash // Note: for text inputs, the client only reads from the "key" paramater @@ -364,25 +395,7 @@ function insertCanvasElements() { // We are hiding the text input behind button because opacity was causing problems. hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;"; hiddenInput.value = " " //Allows delete to be detected before input is changed - hiddenInput.addEventListener("input", function(e) { - hiddenInput.value = " "; // We need a character to detect deleting - if(e.inputType == 'insertText') { - let inputData = e.data.charAt(0); - let isShift = (inputData.toLowerCase() != inputData); - if(isShift) { - keyEvent("shift", "keydown") - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - keyEvent("shift", "keyup") - } else { - keyEvent(inputData, "keydown"); - keyEvent(inputData, "keyup"); - } - } else if (e.inputType == 'deleteContentForward' || e.inputType == 'deleteContentBackward') { - keyEvent("backspace", "keydown") - keyEvent("backspace", "keyup") - } - }, false); + hiddenInput.addEventListener("input", hiddenInputHandler(e), false); document.body.appendChild(hiddenInput); let keyboardButton = createTouchButton("keyboardButton", "inMenu"); keyboardButton.style.cssText = "top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;"