OMORI_Android/www.rus/js/porting/fps_counter.js

30 lines
No EOL
836 B
JavaScript

// by VienDesu! Poring Team 2023
function create_fps_button() {
const FPSBtn = document.createElement("div");
FPSBtn.className = "fps-button";
FPSBtn.id = "buttonF2";
document.body.appendChild(FPSBtn);
console.log(`Setting up the FPS key...`);
FPSBtn.addEventListener("pointerdown", (event) => {
console.log(`Pointer down for F2`);
event.stopImmediatePropagation();
event.preventDefault();
sendEvent(false, 113);
});
FPSBtn.addEventListener("pointerup", () => {
sendEvent(true, 113);
});
}
function sendEvent(isUp, keycode) {
document.getElementById("GameCanvas").focus();
document.dispatchEvent(new KeyboardEvent(isUp ? 'keyup' : 'keydown', { 'key': '', keyCode: keycode }))
}
window.addEventListener('load', () => {
create_fps_button();
});