Live data from Hacker News

Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

tkainrad.dev

191–200 of 212 posts

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#191
post #187

I actually made a custom MacOS Croatian keyboard layout to work around these issues. It switches to a US layout if ctrl/lalt/cmd are pressed, including switching `Z` and `Y`: https://github.com/ivancuric/mac-hr-sane-layout MacOS is notoriously bad for handling international shortcuts. Eg, `Cmd+[` is back system-wide. To get [ on my keyboard I need to press `AltGr + F`. `Cmd + AltGr + F` doesn't work, of course. Where…

I raise you to MacOS + browser + Citrix + Linux + Other browser with Linux being a farm with different keyboard configurations so you never know what you face when you try to log in (requiring the '@' sign).

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#192
post #100

For Western European devs: do try the "USA International (AltGr dead keys)" layout. It's great for programming and quite good for all the Western European languages (maybe not so much for Eastern European languages that are more creative with diacritics). I wish I'd known about it before spending a lot of time creating my own custom layout for Linux and Windows, although since I went through the trouble that's what I…

I don't know which language you're using but for french I migrated from "US International with dead keys" to "canadian english". I fill that, among other things, simple quotes are easier to type and consistency between OSX and Linux is better. A matter of habits and workload balance I guess.

You are talking about a different layout, which I also dislike.

I'm talking about "AltGr dead keys", in which the quotes are available directly and the accents are entered using e.g. AltGr-'.

I'm using 6 european languages occasionally, of which 3 every day, including French. Of these, Canadian English would be only useful for French (e.g. it does not have a tilde dead key AFAIK) and is still different enough from US to be annoying for programming (e.g. the angle brackets are in the "wrong place"). Certainly a big upgrade from AZERTY though!

EDIT: My remark on the Canadian English layout above is based on the first layout that showed up when I googled it, but now I noticed that a lot of different variants come up in the search and I don't know which one you're using. In any event, they all seem to be weaker either for programming or for non-FR/EN languages or both.

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#193
post #138

Earlier quoted context omitted.

Really shows how useful macs having 4 modifier keys (versus PC’s 3) is. Also the better (though not perfect) matching of scopes and modkeys: on macs, command / control / option tend to affect different system areas entirely (with command taking precedence, then control, although control and option are rarely used together).

I do like Cmd+c vs Ctrl+c on a mac. On linux I've changed my terminal to use Ctrl+Shift+c instead of Ctrl+c for ^C because I kept accidentally killing programs when trying to copy text with Ctrl+c which works in every app except terminals...

I recently discover that if you remap Ctrl+C to Copy in a Linux terminal, you still get ^C when nothing is selected. It has made the experience so much better.

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#194
post #85

For Western European devs: do try the "USA International (AltGr dead keys)" layout. It's great for programming and quite good for all the Western European languages (maybe not so much for Eastern European languages that are more creative with diacritics). I wish I'd known about it before spending a lot of time creating my own custom layout for Linux and Windows, although since I went through the trouble that's what I…

It totally f—ks up handling of quotes though. I just cannot stand it, personally. These days, on Windows, I use the Colemak layout, which has a alt-` meta-combo to type common accented letters - I assign that to caps-lock+A with AutoHotKey, and “Bob est ton oncle”.

I believe you are talking about a different layout, "US International with dead keys".

I'm talking about "AltGr dead keys", in which the quotes are available directly and the accents are entered using e.g. AltGr-'.

It's not available out of the box in Windows but you can easily find ready to install layouts online.

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#195

Earlier quoted context omitted.

Not sure if I agree with this summary of my article. For most web apps with relatively few keyboard shortcuts, I would actually recommend to use keypress. keyCode/which/charCode work when used with keypress. The article mentions an open-source example that does it this way and works fine on international layouts: Discourse

Well, maybe you should go edit MDN because it has a giant red "DEPRECATED" at the top of keypress https://developer.mozilla.org/en-US/docs/Web/API/Document/ke...

Never said it wasn't deprecated. It still works much better than using keydown with keycode. For most apps and layouts, it's a sufficient solution.

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#196
post #190

I mostly write in English (plus Clojure, shell, and C#), but often also in Spanish, French and Finnish. I've found that a standard QWERTY/US layout with a Compose key is the best option. It gives you a decent layout for coding and shell related characters, and all diacritics (and plenty more) are a 3 keystroke chain away (with no chording). Even when writing French, which requires a lot of accents, I find it more flu…

Which azerty? French or Belgian? I find the Belgian one is actually very well suited to programming, with easy access to all common symbols. I can't speak to the French one, but from a quick search it does look insupportable .

I've only used the French one (for about 5 years, while living in France... it was awful)

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#197

I mostly write in English (plus Clojure, shell, and C#), but often also in Spanish, French and Finnish. I've found that a standard QWERTY/US layout with a Compose key is the best option. It gives you a decent layout for coding and shell related characters, and all diacritics (and plenty more) are a 3 keystroke chain away (with no chording). Even when writing French, which requires a lot of accents, I find it more flu…

I like the default Mac US/International English/British layouts (they're almost the same as each other). Mac users are graced by an OS that actually uses the Option (Alt) key on every letter to do something useful. You can type all manner of diacritics and such without using a non-standard layout! It works great for English, German, Swedish, Spanish, French, and perhaps more. I only wish there was good support for it…

I'm no longer using Macs for work, but while the option key does enable useful stuff, you can do even better with Karabiner elements and a Compose key there as well :)

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#198
post #166

TL;DR. Don't use keypress, it's deprecated. Don't use 'keyCode', 'which', 'char' which are all deprecated. Do use 'key' Another issue I run into is forms that dismiss via keydown and escape. I type in Japanese which means I'm using an IME. An IME, or at least the Japanese IME, you type characters and they appear with possible completions. They haven't actually been given to the app yet. Pressing Escape cancels the co…

Question then - what do you use functionally to replace "Escape" in your daily use? As a native English-speaking engineer, the escape button has a history of doing exactly what you're suggesting it not do going back to the beginning of computing.

First of all. Don’t put long forms (i.e. more then a couple of inputs; including checkboxes) in a single dialog modal. Second do listen for keypresses on the dialog it self (not window) so that hitting esc on e.g. the URL bar (or the developer console) has no effect on the dialog it self. And thirdly—as parent states—don’t use deprecated properties and listeners, i.e. use `keydown` and `event.key`.

If you follow these three rules feel free to use the esc to close the dialog. I just tested logging `event.key` with hiragana Mozc input device and every keydown while selecting the correct kanji registers as `Process` even cancelling the input with Esc just adds another Process keydown event. I admit it can be frustrating if you double tab Esc accidentally to close the input (second Esc will close the dialog), but that is where rule one comes in, and the accident will only cause the user a minor annoyance.

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#199

Earlier quoted context omitted.

Well, maybe you should go edit MDN because it has a giant red "DEPRECATED" at the top of keypress https://developer.mozilla.org/en-US/docs/Web/API/Document/ke...

Never said it wasn't deprecated. It still works much better than using keydown with keycode. For most apps and layouts, it's a sufficient solution.

What works best is to use `keydown`[1] with `keyboardEvent.key`[2]. Chrome took a while to implement `keyboardEvent.key` and I’m guessing that delay hindered adoption, but for the past few years (since the 5 year old Chrome 51) it is objectively the best—and arguably the only robust—way to figure out which key the user typed.

1: https://developer.mozilla.org/en-US/docs/Web/API/Element/key...

2: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve...

Re: Why keyboard shortcuts don't work on non-US layouts and how devs could fix it

#200
post #28

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 º and ª in that p…

` is bad because it looks like '.

A lot of programming resources I've seen have an explicit explanation that the backtick is a different character than the single quote. Better yet, some fonts make the two almost identical.

Post reply on HN