Unfortunately, there is still one situation where this doesn't work. My webpage contains an iframe object and Javascripts keyboard event listeners do not work while the user is focused inside the iframe. I would have to register the keydown event listener on the iframe content window, but CORS errors prevent me from doing that.
So I would like some help getting AHK to trigger my function in Javascript.
Here is an example of my page:
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>AHK Site</title>
<script>
window.addEventListener("message", (event) => {
if (event.data === 0xAF) {
document.getElementById("message").innerHTML = "Message: Recieved";
}
}, false);
window.addEventListener('keydown', (event) => {
document.getElementById("key").innerHTML = `Key pressed: {${event.key}}`;
}, false);
</script>
</head>
<body>
<div id="message">Message: Not recieved yet</div>
<div id="key">Key pressed: {}</div>
<br />
<iframe width="560" height="315" src="https://www.youtube.com/embed/xMs4e9esYkg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</body>
</html>
My second solution was to use Javascripts message event handler, and trying to use AHK's Send Message command to trigger it. Although I dont really have experience with this and couldnt get it to work either.
This was the AHK code I used
Code: Select all
SendMessage, 0x111, 0xAF, 0, ahk_parent, My Page Title ahk_class Chrome_WidgetWin_1
Ive also seen Chrome.ahk and while that looks like it could work, it seems like overkill for what I need, would require me to start the browser in some debug mode from what I could gather, and I would prefer to have something that works in both Firefox and Chrome and also while installed as a desktop app using Chrome's Progressive Web App feature.
Also, I am trying to avoid writing anything that would require me to set up a server.
If anyone has any suggestions?