alexwidua / aegis

A tiny game to practice shortcuts for the videogame Age of Empires.
https://www.aegis.lol
Other
51 stars 16 forks source link

Disable Alt key that causes the document to lose focus #23

Open aoehk opened 2 months ago

aoehk commented 2 months ago

Quite often I pressed the "Alt" key and then the document loses focus. What do you think adding a feature to discard the alt keydown event?

I did a quick and dirty proof of concept test. At index.html, added the following:

        <script>
            document.addEventListener("keydown", function(e){
                if( e.preventDefault) e.preventDefault();
                if (e.keyCode = 18){
                    return false;
                }
            }, false);
        </script>

This seems to have addressed my need. Not sure if there are any other keys that should be blocked.

If it is good to have this feature, I may try to contribute the change. Maybe there should be an option in the Options screen to enable/disable this feature?! And the blocking code should be at React not at index.html. I don't know React, just JavaScript.

Besides, I think it is good to have a keyboard hotkey for "Start Typing", so when i refresh the page I can start another game instance without using mouse. And best when mouse over "Start Typing" it shows the key, so anyone who plays the game for the first time may know the feature.