Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTML5] KEY_UP event fails to fire when Command is held #1705

Open
Geokureli opened this issue Aug 10, 2023 · 4 comments
Open

[HTML5] KEY_UP event fails to fire when Command is held #1705

Geokureli opened this issue Aug 10, 2023 · 4 comments

Comments

@Geokureli
Copy link
Contributor

Geokureli commented Aug 10, 2023

example:

var field = new TextField();
field.text = "Nothing happening";
field.textColor = 0xFFffffff;
field.x = 100;
field.y = 100;
addChild(field);

addEventListener(Event.ADDED_TO_STAGE,
    function addedToStage(?_)
    {
        stage.addEventListener(KeyboardEvent.KEY_UP,
            function (e)
            {
                if (e.keyCode == FlxKey.C)
                    field.text = "C released";
            }
        );
        
        stage.addEventListener(KeyboardEvent.KEY_DOWN,
            function (e)
            {
                if (e.keyCode == FlxKey.C)
                    field.text = e.ctrlKey ? "Cmd + C pressed" : "C pressed";
            }
        );
    }
);

when I press Cmd+C the test says "Cmd + C pressed", but on release the text does not change until I press and release C again. If I press Cmd+C and release Cmd before C it shows "C released", as expected

Note: Even though I'm using FlxKey.C, I haven't instantiated a FlxGame, or called any flixel utilities that would eat up events with preventDefault or something

@joshtynjala
Copy link
Member

Since Cmd+C is the keyboard shortcut for copy, I wonder if the browser simply isn't dispatching an event to JS when that command is triggered by the user.

Does it make a difference if you call e.preventDefault() in the KEY_DOWN listener? That may stop the browser from copying, which could result in KEY_UP getting dispatched.

@Geokureli
Copy link
Contributor Author

Geokureli commented Aug 10, 2023

Does it make a difference if you call e.preventDefault() in the KEY_DOWN listener? That may stop the browser from copying, which could result in KEY_UP getting dispatched.

the up event is still not* firing after trying:

stage.addEventListener(KeyboardEvent.KEY_DOWN,
    function (e)
    {
        if (e.keyCode == C)
        {
            if (e.ctrlKey)
            {
                field.text = "Cmd + C pressed";
                e.preventDefault();
            }
            else
            {
                field.text = "C pressed";
            }
        }
    }
);

@player-03
Copy link
Contributor

Does this happen with keys other than C (or V)?

@Geokureli
Copy link
Contributor Author

this seems to happen with all keys, but i can now confirm that that e.preventDefault does prevent the normal action of the key combo, except cmd + w and cmd + q (close the window). notably, cmd + h normally hides the active window, and that is prevented. I assume hide, just like W or Q are system commands and not browser commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants