mirror of
https://github.com/FlamedDogo99/EaglerMobile.git
synced 2024-11-24 04:56:04 -08:00
Added android workaround
Also I accidentally converted all the tabs to spaces, thus the large diff. I think this will be the standard from now on
This commit is contained in:
parent
22fb12d51a
commit
aed6d14c13
|
@ -30,20 +30,56 @@ window.sprintLock = false;
|
|||
var previousTouchX = null;
|
||||
var previousTouchY = null;
|
||||
var startTouchX = null;
|
||||
// Ignores any keydown event that doesn't have the isValid parameter.
|
||||
const proto = EventTarget.prototype;
|
||||
const _addEventListener = EventTarget.prototype.addEventListener;
|
||||
Object.defineProperty(proto, "addEventListener", {
|
||||
value: function (type, fn, ...rest) {
|
||||
_addEventListener.call(this, type, function(...args) {
|
||||
if(type === 'keydown' && (!args[0].isValid)) {
|
||||
return;
|
||||
}
|
||||
return fn.apply(this, args);
|
||||
}, ...rest);
|
||||
}
|
||||
});
|
||||
//Allows keyboard to type in input
|
||||
const _preventDefault = Event.prototype.preventDefault;
|
||||
Object.defineProperty(Event.prototype, "preventDefault", {
|
||||
value: function () {
|
||||
if(document.activeElement.id != "hiddenInput") {
|
||||
_preventDefault.call(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Key and mouse events
|
||||
function keyEvent(name, state) {
|
||||
const keyName = name.toUpperCase().charCodeAt(0)
|
||||
window.dispatchEvent(new KeyboardEvent(state, {
|
||||
const keyName = name.toUpperCase().charCodeAt(0);
|
||||
let evt = new KeyboardEvent(state, {
|
||||
key: name,
|
||||
keyCode: keyName,
|
||||
which: keyName
|
||||
}));
|
||||
});
|
||||
evt.isValid = true; // Disables fix for bad keyboard input
|
||||
window.dispatchEvent(evt);
|
||||
}
|
||||
function shiftKeyEvent(state) {
|
||||
window.dispatchEvent(new KeyboardEvent(state, {
|
||||
let evt = new KeyboardEvent(state, {
|
||||
key: "Shift",
|
||||
keyCode: 16,
|
||||
which: 16
|
||||
}));
|
||||
});
|
||||
evt.isValid = true; // Disables fix for bad keyboard input
|
||||
window.dispatchEvent(evt);
|
||||
}
|
||||
function deleteKeyEvent(state) {
|
||||
let evt = new KeyboardEvent(state, {
|
||||
key: "Backspace",
|
||||
keyCode: 8,
|
||||
which: 8
|
||||
});
|
||||
evt.isValid = true; // Disables fix for bad keyboard input
|
||||
window.dispatchEvent(evt);
|
||||
}
|
||||
function mouseEvent(number, state, canvas) {
|
||||
canvas.dispatchEvent(new PointerEvent(state, {"button": number}))
|
||||
|
@ -325,6 +361,26 @@ function insertCanvasElements() {
|
|||
let hiddenInput = document.createElement('input', true);
|
||||
hiddenInput.id = "hiddenInput"
|
||||
hiddenInput.style.cssText = "opacity:0;z-index:-99999";
|
||||
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) {
|
||||
shiftKeyEvent("keydown");
|
||||
keyEvent(inputData, "keydown");
|
||||
keyEvent(inputData, "keyup");
|
||||
shiftKeyEvent("keyup");
|
||||
} else {
|
||||
keyEvent(inputData, "keydown");
|
||||
keyEvent(inputData, "keyup");
|
||||
}
|
||||
} else if (e.inputType == 'deleteContentForward' || e.inputType == 'deleteContentBackward') {
|
||||
deleteKeyEvent("keydown");
|
||||
deleteKeyEvent("keyup")
|
||||
}
|
||||
}, 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