mirror of
https://github.com/FlamedDogo99/EaglerMobile.git
synced 2024-11-09 14:06:05 -08:00
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
This commit is contained in:
parent
2ed6365c42
commit
f5e74945ec
|
@ -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;"
|
||||
|
|
Loading…
Reference in New Issue
Block a user