Replies: 3 comments 9 replies
-
I would love to do that, but here's a simple problem: The approach you are suggesting is great if you want to listen to the produced key, but there are a lot of cases where you want to listen for layout independent keys. I am leaning more and more to the conclusion that it would be best to have two hooks. One listening to key, the other one to keyCode. But then the API would get really confusing, because it is not intuitive to most devs why there is a difference in Hotkeys are hard 😄 |
Beta Was this translation helpful? Give feedback.
-
That's exactly the point of the As opposed to the This leads to one of the most used shortcuts - undo: ctrl + z - being messed with sometimes. There are programs that handle it by requiring the user to actually stretch their hands and reach all the way to the middle of the top row while pressing ctrl (or turn it into a two handed gesture), but some actually just treat the hotkey as being "press ctrl and the key to the right of the left shift, we don't care what symbol it produces" [being If we were to get rid of the further translation of keys (the ps.: I understand that this would increase verbosity, but the current "convenience" of treating hotkey strings leniently and trying to guess what the developer meant is part of what leads to ambiguity. |
Beta Was this translation helpful? Give feedback.
-
After deciding to implement this and submit as a pull request I am starting to realize what might actually pose a problem with my suggestion. 😑 There doesn't seem to be an easy way to map keycodes to their respectively produced symbols under the currently active keyboard layout of the user, which makes showing meaningful hints very difficult. |
Beta Was this translation helpful? Give feedback.
-
I second the recently opened issue (#1006) by @ptxmac, the strangely named key mappings have also caught my attention, and I would consider them to be an issue with the current code, but since you asked for the topic to be moved over to a discussion, I'm responding here.
I think that the
code
property ofKeyboardEvent
that is currently in use is the proper way to go about this, as that one maps to the actual key instead of the symbol produced while typing.To quote MDN:
Im my opinion hotkeys should "stay in place" on different layouts even if the symbols are moving around, since they are (usually) meant to be comfortable and stored in muscle memory. Let's say that my application has the combination
ctrl+s
bound to an action, that is a very convenient one handed gesture on most of the layouts, but in case someone would be using let's say a 40% Dvorak layout, they would have practically no way to execute the action one-handed if it moved with the letters
. (I know, that's a pretty contrived example, but you get what I mean.)One drawback of this that I can think of is the possible disconnection from mnemonics, such as
ctrl+s
for "save",ctrl+a
for "all",ctrl+c
for "copy" and so on, but those also partially lose their value with locale changes that bring the layout variations in the first place, and to be fair, most layouts only move the symbols around, not the basic letters of the alphabet, and symbols can't serve as mnemonics anyway.My suggestion would be to get rid of the entire
mappedKeys
object andmapKey
function and instead use the proper names as provided here:https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values
This would also remove the necessity for the extra complexity introduced by
combinationKey
andsplitKey
, as+
and,
don't appear among the list of codes anyway.I'm interested to see what @JohannesKlauss and others think about this!
ps.: I understand that the fact that I've questioned one of the recently merged PRs (#980), opened a new issue (#1013) and am starting a discussion as well on the same day might make it seem like I'm a bit overzealous, but I can assure you that I don't have any invasive motives! I'm just very happy to see that the trends are showing that an alternative to the now more than three years ago abandoned
react-hotkeys
library is rising, and would like to switch to it as soon as possible, but I need some things to be fixed before I can make the transition. I would also like to ensure that the code doesn't get unnecessarily bloated or complicated, that's why I'm also questioning the importance of the recently addedignoreEventWhen
option. I am very happy to see that in it's current state the library has less than 500 lines of source, only about one tenth of the previously mentioned and still most widely usedreact-hotkeys
, which had almost 5000...Beta Was this translation helpful? Give feedback.
All reactions