I have a weird problem that is happening only on Chrome Windows 10, but not on Windows 11 or OSX. Im using Electron (nothing more than Javascript).
My goal is, when I click inside an iframe, I need to be able to detect if either "S" or "B"is being held down. The code below works perfectly fine on latest Chrome (OSX and Windows 11). For some weird reason, I cant get the console log click to print and execute the function. It seems that when either "s" or "b" is held down, the clickEventHandler does not trigger (it does not print the console log message) on Windows 10.
window.is_key_down = (() => {
window.keystate = {};
window.ifra = document.querySelector('iframe');
ifra.contentDocument.body.addEventListener('keyup', (e) => keystate[e.key] = false);
ifra.contentDocument.body.addEventListener('keydown', (e) => keystate[e.key] = true);
return (key) => keystate.hasOwnProperty(key) && keystate[key] || false;
})();
var clickEventHandler = function(){
console.log('Click On Iframe Detected')
//Can also Replace with is_key_down("s")
if(keystate.s){
window.placeAD("side1")
//keystate={}
}
//Can also Replace with is_key_down("b")
if(keystate.b){
window.placeAD("side2")
//keystate={}
}
}
var iframe = document.querySelector('iframe');
iframe.contentDocument.body.addEventListener('click',clickEventHandler);
I am more than puzzled, so perhaps a different approach to work on both would be great.
I have tried many different combinations and other tricks, but the clickEventHandler is not triggered if "s" or "b" are being held down when clicking. If no keys are being held down, the console log prints just fine.
Thanks in advance!!