[HN Gopher] Why Keyboard Shortcuts don't work on non-US Layouts ...
       ___________________________________________________________________
        
       Why Keyboard Shortcuts don't work on non-US Layouts and how Devs
       could fix it
        
       Author : tkainrad
       Score  : 101 points
       Date   : 2021-04-08 19:56 UTC (3 hours ago)
        
 (HTM) web link (tkainrad.dev)
 (TXT) w3m dump (tkainrad.dev)
        
       | gmac wrote:
       | It really surprised and disappointed me recently that native
       | macOS apps have the same problem outlined here. For example, the
       | standard system-wide 'back' shortcut (e.g. in Safari, Finder,
       | Preview) is Cmd+[, but this is inoperable in many keyboard
       | layouts that don't have any key that produces [ without
       | modifiers.
       | 
       | (For context: I was writing a simple mouse gestures utility that
       | sends that keyboard shortcut to accomplish backward navigation
       | for an appropriate gesture, but discovered this to be unreliable
       | across keyboard layouts).
        
         | [deleted]
        
         | lxgr wrote:
         | It's even worse on ISO keyboards (the ones with the large
         | return key).
         | 
         | There's a physically different key arrangement on these, so
         | even when switching to the US lay-out, some important system-
         | wide shortcuts are still impossible to type (most notably the
         | one for ,,switch to different window").
        
       | rcarmo wrote:
       | I've gotten so used to switching between keyboard layouts when
       | moving from e-mail to coding that I don't think about this much,
       | but it can be tremendously irritating when I'm on a new machine
       | or just forget to switch.
       | 
       | (pt-PT keyboard, parenthesis and brackets are either an off-by-
       | one or require Alt-Gr+Shift to type.)
       | 
       | Using a US keyboard layout for a while really drives home how
       | much it influenced popular CLI character choices (like path
       | separators, pipe characters, etc.), too.
        
       | huachimingo wrote:
       | And then you discover non-ASCII world...
        
       | vxNsr wrote:
       | The author spends a lot of time explaining the APIs that have
       | been deprecated but doesn't say which one is the correct one to
       | use now...
        
       | sleavey wrote:
       | > For example, on my German layout, / is produced via Shift+7.
       | 
       | This is my #1 annoyance with German keyboards as someone who
       | learned a UK layout and who needs to do lots of programming and
       | terminal hacking (#2 is the swapping of Y and Z). I take it this
       | layout was invented before Unix and its heavy use of forward
       | slashes, but it does show how shortcuts are rather
       | discriminatory. I know more than a few Germans who use UK or US
       | keyboards because they dislike this unhappy feature.
        
         | young_unixer wrote:
         | I'm Chilean and I use the ANSI US layout because /, < and > are
         | much easier to type than using ISO keyboards.
         | 
         | When I need to type Spanish characters like aeiou, n, etc. I
         | switch to latin american ISO layout using WIN + Spacebar and
         | then switch back.
        
           | Svip wrote:
           | Why not just use US Intl, and use ALT GR to produce a, e, i,
           | o, u and n, along with ae, o and a?
           | 
           | I have a strange ISO/ANSI US keyboard, with an ANSI left
           | shift and an ISO enter key.
        
             | young_unixer wrote:
             | I didn't know about the US intl layout when I decided to
             | make the switch, and I don't know if it's worth to learn it
             | now.
        
               | Svip wrote:
               | I used to switch between US and DK layouts, it's just so
               | much easier to just have one layout. In my opinion,
               | learning US Intl is worth it. Besides, it's pretty
               | predictable for Spanish characters: a = altgr+a, e =
               | altgr+e and so on.
        
         | lxgr wrote:
         | > I take it this layout was invented before Unix and its heavy
         | use of forward slashes
         | 
         | My guess would be that Unix chose many of its special
         | characters and keyboard shortcuts precisely because they were
         | easy to type on a US keyboard.
        
         | sdlion wrote:
         | Same problem with latin american keyboards found just a few
         | kilometers south the US. If I remember correctly, the default
         | modifier key in VIM is next to imposible to press on a l-a
         | keyboard. It was ` ?
        
           | toxik wrote:
           | You mean the default prefix key. You really really don't need
           | to use prefix keys, like at all, in normal Vim use.
        
       | zigzag312 wrote:
       | Dead keys are particularly fun, as it takes two key presses to
       | produce a result. Accessibility of keyboards/layout could indeed
       | be improved. I switched to custom US layout, because of too many
       | issues with a non-US layout. My custom layout uses AltGr
       | combinations to add a few local characters. It is a bit clumsy,
       | but at least keyboard shortcuts work most of the time.
        
         | pornel wrote:
         | Polish has a "traditional" (typewriter) and "programmer's" (US
         | + AltGr) variants of the keyboard layout. _Everyone_ uses the
         | "programmer's" one, even people who don't know what programming
         | is.
        
       | corty wrote:
       | The fix is to buy US keyboards and configure a compose key for
       | non-a-z characters.
        
       | kps wrote:
       | The root of the problem is what this article correctly describes
       | as the deprecated properties `keyCode` et al. These are essential
       | raw Windows events that browsers in the '90s unwisely decided to
       | expose. For any platform that is _not_ Windows, these have to be
       | emulated, which is not at all simple, since the details vary
       | according to particular Windows keyboard layouts.
        
         | stkdump wrote:
         | It's not a windows thing. These are the codes that the hardware
         | uses, on all platforms.
        
       | MattGaiser wrote:
       | > What baffles me is that the problem exists in apps used by
       | millions of people every day, developed by gigantic corporations
       | who pride themselves with having the best engineers in the world.
       | Why is this baffling? Because the underlying technical issues are
       | rather trivial!
       | 
       | > Hint for developers: Switch your computer's keyboard layout to
       | something other than US to debug your application's shortcut
       | handling on different layouts.
       | 
       | The problem with this and all the other X is broken and should be
       | tested articles is that the testing burden is already enormous.
       | Plenty of companies don't even test with Firefox and/or Safari.
       | 
       | That's really the problem that needs to be solved. How to reduce
       | the testing burden.
        
         | layer8 wrote:
         | If there was a standard way to define hotkey bindings, a simple
         | linter could take care of that. It just shows how far we still
         | have to go in terms of good UI creation tooling.
        
           | jakear wrote:
           | This is part of why I'd like to see more VSCode-as-an-OS
           | (disclaimer work on VSCode)... imagine writing only the code
           | to go from bytes on disk => view and back, and getting for
           | free: version control, command palette, keybindings,
           | Windows/Mac/Linux/Web support, file explorer, tabs, split
           | views, hot exit, etc etc etc.
        
         | tkainrad wrote:
         | I agree to some extent. However, I have outlined a few very
         | simple approaches. At the very least, developers could stop
         | using special characters for their most important shortcut
         | bindings.
        
         | smnrchrds wrote:
         | For a 10-person startup, that's fair. For a company like Google
         | , with offices in Germany and France and hundreds of engineers
         | from any nationality, not so much. Other companies fall
         | somewhere in between based on their headcount and global reach.
        
       | adamzochowski wrote:
       | There is also a whole slew of issues with Polish characters.
       | Polish keyboard setup relies on "right-alt" and a letter to get
       | it's diacritics variation. Ie: 'a' is 'right-alt'+a
       | 
       | Windows for backwards compatibility reports 'right-alt' as
       | 'alt+control'.
       | 
       | Many applications developers assign key combos with no negative
       | checks. So 'ctrl-s', typically used for save gets triggered when
       | user wants to type 's'. To repeat, "right-alt"+"s" is reported as
       | "alt"+"control"+"s", which triggers crappy "control"+"s" checks.
       | 
       | Similar scenarios happen many places that check for
       | 'alt'+'letter' without checking if control also is not pressed.
       | 
       | Microsoft thread for team user voice issues on this
       | https://microsoftteams.uservoice.com/forums/555103-public/su...
       | 
       | or Medium's developer talking about 's' and 'ctrl'+'s'.
       | https://medium.engineering/the-curious-case-of-disappearing-...
        
         | toxik wrote:
         | Seems easy to fix
         | 
         | > Windows for backwards compatibility reports 'right-alt' as
         | 'alt+control'.
         | 
         | There's your problem, right there
        
           | adamzochowski wrote:
           | The backwards compatibility is for physical keyboards. So
           | that a keyboard with just one alt can still trigger polish
           | letters.
           | 
           | I don't know how other OSes allow for users to trigger
           | "right-alt" when the keyboard has only one alt character.
        
           | ynik wrote:
           | That also works the other way around -- you can use
           | alt+control instead of right alt.
           | 
           | This may make sense to do with some of the more annoying key
           | combinations, e.g. the German layout requires pressing
           | AltGr+7 for '{'. Both keys individually are usually pressed
           | by the right hand, but pressing the combination with the
           | right hand alone is a very uncomfortable hand position.
        
           | samatman wrote:
           | No, there are at least two problems here.
           | 
           | An application shouldn't accept ctrl+alt+n as either ctrl+n
           | or alt+n. That is simply a bug, no way around it.
        
         | gabereiser wrote:
         | This is actually fascinating to me. I've dealt with keyboard
         | input numerous times (not WinForms or browser either) and I
         | always devised a way where control characters were a bitwise
         | with the keycode. You would have to include this in any input
         | mapping. I can totally see where this key combo issue would be
         | a problem in a UI scenario in the browser or other shortcut-
         | laden desktop app.
        
         | [deleted]
        
         | fasteddie wrote:
         | ah, the Polish Alt-Right is a problem?
        
       | Joeri wrote:
       | On a tangent, why are non-qwerty keyboards so poorly designed for
       | programming? And specifically, why is apple's azerty layout so
       | terrible?
       | 
       | Just look at this image: https://i.stack.imgur.com/3LL8a.png
       | 
       | Can you find the [ and ] keys? If you're having trouble, it's
       | because you have to use 2 (two!) modifier keys and activate the (
       | or ) keys, which themselves are clumsily placed. This cannot be
       | typed one-handed in a comfortable way. Apple's azerty layout is
       | unique in this, as regular azerty puts those keys in a more
       | sensible place. I keep wondering: why does apple make me do a
       | Vulcan nerve pinch every time I want to index an array?
        
         | StavrosK wrote:
         | I remapped all those keys to Tab+righthand, so to type the
         | curly brace I press Tab+j. It's fantastic.
        
         | mattnewton wrote:
         | I think the answer is that their engineers overwhelmingly use
         | the English layout keyboards and work in Cupertino. Most
         | improvements to coding on a Mac I have seen have a design-for-
         | self element where apple employees are eating their own dog
         | food and want to improve the taste.
        
           | tesseract wrote:
           | C was famously designed in Murray Hill on a system with
           | Teletype 37s, which featured then-fairly-novel { and } keys
           | (as it so happens, the shifted versions of [ and ]).
        
         | desert_boi wrote:
         | QWERTY is awful for programming. I use
         | https://www.kaufmann.no/roland/dvorak/. which puts control
         | characters on the number row. `&[{}(=*)+]` is 1 to 0.
        
         | slightwinder wrote:
         | Most keyboard-layouts predate programming-languages, because
         | they were designed for typewrites decades before the first
         | modern computers even existed. So there did gave much to usage
         | of special chara back then. Additionally most languages were
         | designed by americans, on US-layout, which had a great impact
         | on usages of different char in our digital world. Like for
         | example the usage of @, which AFAIK was only used for e-mail
         | because there was no other free char on the developers keyboard
         | available.
        
         | rmetzler wrote:
         | It's the other way around. The keyboard was the foundation for
         | the programming languages and shortcuts, like moving with hjkl
         | in vim. No German keyboard user would have created a language
         | like C with curly braces, when you would break your fingers
         | typing this (alt 8 is {, alt 9 is }, and alt+5 is [, alt+6 is ]
         | ).
         | 
         | I use a US keyboard for that exact reason
        
       | j1elo wrote:
       | As a kid, I remember being utterly confused, when most games with
       | a console would have the key ` to open it. _WTF is the key ` and
       | where is it?_
       | 
       | For a kid it wasn't that easy to understand that there are such
       | things as different keyboard layouts. Turns out that ` is a
       | single key press to the left of the '1', in English, while it is
       | a bit obscure character to write in other languages. In mine, you
       | have o and a in that place... so no ` at sight.
       | 
       | But game devs assume that ` is just a keypress away in a
       | confortable area of the keyboard, and it became the de facto way
       | to open in-game consoles. Oh well.
        
         | Macha wrote:
         | Also programming languages used it as an alias for exec. Even
         | if you have a ` key, on some layouts (such as the Irish
         | keyboard layout) it can be a weird key to type due to dead key
         | behaviour, often requiring multiple presses to respond and
         | eating the next keypress.
        
       | Havoc wrote:
       | Also while we're at it...fix this for bitlocker. Makes special
       | characters in passwords a nightmare and you need to memorize
       | where that stupid character is...
        
       | joshuakarl wrote:
       | I'm french canadian and the most satisfying solution I've found
       | is to keep switching from one keyboard layout to another. I
       | mostly use the american layout when I code, and the french
       | canadian one to communicate. I got used to it in about a week.
        
         | stkdump wrote:
         | I now exclusively use US-International No Dead Keys. I just use
         | the right alt key + qpys to get aouss. I hate having to switch
         | layouts and switching layouts accidentally while typing. Those
         | key combinations are not worse than []{}\ on the german layout.
        
           | layer8 wrote:
           | I use a US keyboard with Caps Lock mapped to Compose (using
           | WinCompose [0]), which lets me type any Unicode character I
           | need. Totally agree that switching layouts is a pain.
           | 
           | [0] https://github.com/samhocevar/wincompose
        
       | 6t6t6t6 wrote:
       | That's why I switched to American keyboard some time ago.
        
       | wodenokoto wrote:
       | In order to write backtick, I have to shift-click the key left to
       | backspace and then click spacebar.
       | 
       | Tilde ~ is similar: option-click and then space.
       | 
       | This makes the out-of-the-box keyboard shortcut for switching
       | window on macOS unreachable on my macbook pro.
       | 
       | There are several default shortcuts on osx that are unreachable
       | from international keyboards.
        
       | PureParadigm wrote:
       | It's not just international keyboards that are affected by this.
       | I'm a Dvorak user so I run into these issues from time to time.
       | 
       | As the article explains, there is a difference between the
       | physical keyCode and character it corresponds to. Which to use
       | really depends on what it is being used for, and there are
       | situations for both. The article suggests checking the character
       | typed, but this is not always the correct way to do it.
       | 
       | For instance, the most annoying are games which default to WASD
       | based on the letter typed and not the physical keys (I've seen
       | this both in web app and native games). Using WASD based on
       | letters simply does not make sense because the whole purpose is
       | to mimic arrow keys. If you base it off of letters typed, then on
       | Dvorak it's like if you used ,A;H on Qwerty which makes
       | absolutely no sense for directional navigation.
       | 
       | For shortcuts where the letter has a meaning, then you might want
       | to look at the actual character. But beware that even
       | alphanumeric keys are not always in the same place because of
       | layouts such as Dvorak and Colemak.
        
         | setr wrote:
         | > For instance, the most annoying are games which default to
         | WASD based on the letter typed and not the physical keys
         | 
         | Is it even possible to do anything else? I can't imagine
         | keyboards report their physical layout..
        
           | powersnail wrote:
           | The only possibility is to allow the user to assign custom
           | keys, which is pretty common.
           | 
           | It's impossible to know the physical layout for absolute
           | certainty. For all you know, my "Enter" could be a pedal
           | under the desk.
        
           | nitrogen wrote:
           | Scancodes from PS/2 keyboards are layout-based.
        
           | desert_boi wrote:
           | Starcraft II had a grid (I don't remember the actual name)
           | mode keyboard layout that worked perfectly with Dvorak
           | without having to remap keys.
           | 
           | Other games like the Java version of minecraft didn't work
           | with Dvorak when I tried them. Even with key remapping.
        
           | 1123581321 wrote:
           | A few games map based on the key codes. For example, SC2 will
           | get grid layout right on Dvorak or Colemak without any
           | remapping. It did take me directly emailing a designer, who
           | passed it on to the developers, though. ;)
        
           | snuxoll wrote:
           | Physical layout is mostly irrelevant, different keycap label
           | arrangements use the same keycodes - the input system in your
           | OS or application uses a keyboard layout to translate those
           | into what you want to type.
           | 
           | Windows, macOS and the various input libraries on Linux
           | provide ways to query the key map - and a number of games do
           | use this to provide localized bindings (Ubisoft and Blizzard
           | are notorious for doing this right, something I appreciate as
           | a dvorak user who hates dealing with rebinding or constantly
           | having to toggle layouts). As far as the browser there is
           | coming support for reading the keyboard layout as well:
           | https://developer.mozilla.org/en-
           | US/docs/Web/API/Keyboard/ge...
        
         | stkdump wrote:
         | Is there a programmatic way to figure out what letter
         | corresponds to a given keycode without that key being pressed?
         | Because you may have to display that info somewhere to give an
         | indication what the user has to press.
        
         | opan wrote:
         | I've used dvorak and now workman and I don't mind the shortcuts
         | moving around.
         | 
         | The biggest annoyance for me is if you want to sometimes use
         | hardware-level dvorak or another layout (which expects
         | software-level qwerty) and sometimes use it in software. Like,
         | if your keyboard runs QMK but you use it with a laptop and
         | might want to use the laptop's built-in keyboard if you take it
         | on the go.
         | 
         | GTK also has some weird issues if you have multiple layouts
         | enabled where the shortcuts are in the wrong place and don't
         | all work (happens in Dino and Gedit). So, I now have only
         | qwerty enabled in Sway and I'll just edit the config if I ever
         | need to change virtual layouts instead of doing it with a
         | couple keypresses.
        
         | carabiner wrote:
         | OS X's solution works perfectly: Dvorak + QWERTY shortcuts
         | layout. It's brilliant and elegant, Windows needs to implement
         | the same thing (revert to QWERTY when holding the ctrl or
         | windows keys).
        
       | dgan wrote:
       | I am using a French azerty keyboard, but since '[]' and '{}' are
       | in wierd locations,i always remap them to US-alike. This breaks
       | the diacritics, but oh well
       | 
       | I also like my ';' and '.' swapped, because dot is clearly more
       | useful when typing in terminal
        
       ___________________________________________________________________
       (page generated 2021-04-08 23:00 UTC)