Capturing keystrokes to run automations

I’m hoping to get my dashboard to support keystrokes. I’d like to be to hit the “left” key from my laptop to trigger a service call to Android TV.

I’ve created a javascript module that can capture keystrokes, but not finding documentation on how to call an automation from the module.

Any thoughts?

Call the API?

Thanks I’m not sure how to call the API from javascript. Any pointers?

Mr G says html - How to call a REST web service API from JavaScript? - Stack Overflow

Thanks - I decided to move all the logic into an automation, so the script is now pretty simple and only triggers a webhook if I’m holding down the alt/option key.

document.onkeydown = function (evt) {
    evt = evt || window.event;
    if (evt.altKey) {
        const xhr = new XMLHttpRequest();
        xhr.open("POST", '/api/webhook/INSERT_YOUR_ID', true);
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        xhr.send(JSON.stringify({ "key": evt.key }));
    }
};