Update `triggerKeyEvent` to handle `code` and `key`.
See original GitHub issueFrom https://github.com/emberjs/ember-test-helpers/pull/258#discussion_r155963086:
When I initially copied
keyEvent
, I continued to usekeyCode
as the main way to set the key, but it seems to be deprecated and the new alternatives are KeyboardEvent.code and KeyboardEvent.key, specially the last one.Perhaps we might want to start using it, or maybe assume that integers mean
keyCode
and strings meankey
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Is it possible to simulate key press events programmatically?
The answer is: There is no way to programmatically trigger input keys in the sandboxed browser environment under normal circumstances. Bottomline: I am...
Read more >KeyboardEvent.key - Web APIs | MDN
The KeyboardEvent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state ...
Read more >KeyEvent - Android Developers
Key code constant: L1 Button key. On a game controller, the L1 button should be either the button labeled L1 (or L) or...
Read more >.keypress() | jQuery API Documentation
To trigger the event manually, apply .keypress() without an argument: ... Note that keydown and keyup provide a code indicating which key is...
Read more >Keyboard: keydown and keyup - The Modern JavaScript Tutorial
So, event.code may match a wrong character for unexpected layout. Same letters in different layouts may map to different physical keys, leading ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here,
code
isn’t set. Here is the workaround:Also will provide squiggly red lines if you are using TS 😦. May I suggest this API:
where
Props
is theKeyboardEventInit
. This way it is BC but will provide the flexibility we have to deal with when handling key events.Sorry to resurrect an old issue, but was the
code
property intentionally left out of the fix here? I’ve got a failing test because we’re using a keyboard shortcut that relies on thecode
property. I had skipped the test and added a comment linking to this issue, thinking that it would eventually be fixed. We can refactor to use something else, but is there a reason whycode
was not implemented?From my understanding,
key
andcode
are both supported for different reasons-key
gives you the string ‘value’ of a keypress, whereascode
is useful for telling which physical button was pressed, regardless of keyboard layout or language.