Diacritic Key

ArtoriasEdgeworth

14 Mar 2017, 17:24

Hello!
I was wondering if anyone out there had ever programmed a key for generating diacritics.
I was thinking that the key would work like a sort of toggle. Press the diacritic key, then press the letter you want the diacritic over. Then, type the character you want the diacritic to be. For instance:
Diacritic, then U, then : would result in a Ü.
Thank you!

User avatar
pr0ximity

14 Mar 2017, 17:36

I've done a fair amount of "press for Esc, hold and press something else for Ctrl+something" bindings in Karabiner, so it might be possible to make every character a Fn key when held that exposes a layer of all of the decorated single characters. In Karabiner however this results in a noticeable delay when typing so you can't really type that fast. But the idea may be applicable to other software that isn't as limited.

I assume you don't want a simple layer of combining marks, like typing U then Fn+: for the umlaut combining character?

User avatar
zslane

14 Mar 2017, 17:49

Yes, that is generally what R-Alt is used for these days if you have an international keyboard layout running. If your default keyboard layout under Window, for instance, is English US, then just add the US International layout, and when that is active, the R-Alt key becomes an Alt Graph key and functions pretty much exactly as you are describing.

User avatar
Ratfink

14 Mar 2017, 18:42

zslane wrote: Yes, that is generally what R-Alt is used for these days if you have an international keyboard layout running. If your default keyboard layout under Window, for instance, is English US, then just add the US International layout, and when that is active, the R-Alt key becomes an Alt Graph key and functions pretty much exactly as you are describing.
Yep, that works here in Gnome 3 as well. I can press [Right Alt][C][C][C][P] and out pops a ☭. :lol:

User avatar
Daniel Beardsmore

14 Mar 2017, 19:12

Please state the nature of the medical emergency your operating system.

In Windows, there's an official keyboard layout building program, which was used to create the United Kingdom International layout that I still use on one PC; this has dead key support. However, recent Windows versions (definitely 8 and 10, and maybe older) have serious bugs with keyboard layouts and they will flip back to US on a whim.

As such, my preference now is to put the dead key handling into AutoHotkey as part of my standard file. I needed AutoHotkey anyway to add custom symbols to (e.g. →, and real minus −), and to extend United Kingdom International with common symbols (the developer of which never responds) and since Windows is broken I figured I'd just use AutoHotkey entirely going forward.

This is all I have right now:

Code: Select all

^!/::deadkey({ a: "á", e: "é", i: "í", o: "ó", u: "ú" })
^!\::deadkey({ a: "à", e: "è", i: "ì", o: "ò", u: "ù" })
^!.::deadkey({ a: "å" })
^!;::deadkey({ a: "ä", e: "ë", i: "ï", o: "ö", u: "ü", y: "ÿ" })

deadkey(keys) {
	Input, key, L1, {esc}{backspace}
	if (!InStr(ErrorLevel, "EndKey:"))
	{
		outKey := keys[key] ? keys[key] : "?"
		Send %outKey%
	}
	return
}
I'll add more in time as I find the need.

I got the idea off the Web somewhere, but I've adapted it to make it cleaner and simpler as well as handle errors better. å is only there because I know someone living in Umeå.

Findecanor

14 Mar 2017, 21:15

ArtoriasEdgeworth wrote: Press the diacritic key, then press the letter you want the diacritic over. Then, type the character you want the diacritic to be.
Many European layouts have "dead keys" for diacritic marks that work that way. In Swedish these are '` (accents) and "^~ (umlaut, roof, tilde) and those are only those that are printed on keycaps - there might be more on Alt Gr combinations.
For instance, ' followed by e becomes é when you press the E key.
If you'd press the Space bar instead of a letter you'd get the symbol representing the diacritic mark on its own. For instance, Alt Gr + "^~ followed by Space is how you type ~ (tilde).

You could get this functionality by making your own custom keymap in a layout editor.
In X under Unix/Linux, you could have changes to your keymap in an input file for the xmodmap command. Then make xmodmap with your layout file run each time you log in.

davkol

14 Mar 2017, 21:42

That or Compose.

Sigmoid

15 Mar 2017, 14:57

As @Findecanor mentioned, this functionality is called a "dead key", and have been in use for as long as computers have the capability to display international alphabets. It has fallen out of favor on national keyboard layouts, as it makes typing slow and uncomfortable, but it is generally kept around to type foreign names and occasional words in an international context.

Actually, in Mac OS, the built-in "US International" keyboard layout has a number of so-called dead keys which do just this. In Linux, there are a number of X11 keyboard layouts that use dead keys too. Both OSes have a human writeable keyboard layout definition format that you can use to define your own dead key sequences, though it's slow and painful work. Like, "Cinderella, while we go to the ball, you code a dead key layout for typing German, Hungarian, Czech and Scandinavian names on an ANSI keyboard" slow and painful, and at least on Mac OS the only existing tool (one called Ukelele) is actually worse than writing the damn things by hand.

ArtoriasEdgeworth

15 Mar 2017, 17:32

Bonus points for the Starcraft reference, Mr. Beardsmore! :lol:

Is there any way for a keyboard controller to be programmed with this ability?

I was looking at ASCII codes, and it looks like I could program a controller to convert those three keypresses into a diacritic'd character.

User avatar
Daniel Beardsmore

15 Mar 2017, 19:28

Starcraft … ??

ArtoriasEdgeworth

15 Mar 2017, 19:56

:oops:
....or not.
It's something your medics can occasionally say.

User avatar
Daniel Beardsmore

15 Mar 2017, 20:10

It's from Star Trek: Voyager. Mostly entertaining for the mind-blowingly, truly incomprehensibly stupid episode "Threshold".

The controller can only send the identity of the key. For example, in the UK AltGr+e = é, but the keyboard can't deliver this. The keyboard only sends AltGr + E and the OS decides how to interpret this. It's a lousy system that locks us into the mess we got into when we decided that keyboards should be as painfully limited as typewriters.

Dead keys are processed by the OS. You could implement dead keys in hardware, but you'd be constrained to the repertoire of the host's layout, and for me I won't tolerate such a limitation.

davkol

15 Mar 2017, 21:10

Well, the keyboard doesn't even send AltGr+E. For example, showkey will output, when pressing keys labeled like that on a standard keyboard:

Code: Select all

key code 56 press
key code 18 press
key code 18 release
key code 56 release
The software keymap translates 56 to AltGr and 18 to E on QWERTY (but F on Colemak), AltGr+E to 'ě' on my customized keymap.

It's technically possible to make the keyboard send Unicode right away, though. QMK and some other firmware supports it, but it might result in unintended behavior in some circumstances.

User avatar
Daniel Beardsmore

15 Mar 2017, 22:46

Not literally AltGr+E, if you're going to be that pedantic. Scancodes tend to be linked to their US functions, although in which case it's Right Alt+E.

davkol

15 Mar 2017, 22:53

We could've been using coordinates from ISO/IEC 9995 instead. :evilgeek:

User avatar
vvp

16 Mar 2017, 11:06

ArtoriasEdgeworth wrote: I was looking at ASCII codes, and it looks like I could program a controller to convert those three keypresses into a diacritic'd character.
Translation of key presses to unicode code points is a responsibility of the keyboard driver in your operating system. You cannot do this in the keyboard controller. Well you could, but then you would need to write a special driver for your operating system.

Look at chapter 10 Keyboard/Keypad Page (0x07) on page 53 of USB HID Usage Tables to get an idea what a standard USB keyboard can send to an operating system.

User avatar
Laser
emacs -nw

16 Mar 2017, 12:23

Not sure if mentioned, maybe it will be useful for anyone: https://github.com/samhocevar/wincompose

ArtoriasEdgeworth

16 Mar 2017, 14:22

Thanks for the sheet, vvp. I'm gonna have to keep a copy of that handy!

I'll do some research on QMK, see what I can make happen.

Entropia

16 Mar 2017, 17:10

I use the US International layout for my ANSI keyboard, but I have adapted it to suit my needs using Autohotkey. So, for instance, I've mapped the Spanish ñ to the right control (or menu or right window key) and some combinations are changed so that they are easy to remember and more intuitive. So, for instance, ralt + e = €, ralt + l = £, ralt + u = ü... and several more. With my script I also changed the behaviour of the `/~, " and ^ keys to work as non-dead keys, because I do not need that behaviour in Spanish. Finally, I also figured out an alternative way to generate certain characters such as the ñ or the ü in a tablet/cell phone way, that is, keeping the n or the u key pressed for some 0,25 seconds.

User avatar
fruitalgorithm

16 Mar 2017, 17:29

The keeping a key pressed to get the diacritics is what macOS has done since a couple of versions. It's not bad, but it kind of interrupts the flow when touch typing. Still pretty useful to keep the number of symbols down you have to remember when using an unfamiliar layout.
diacritics.png
diacritics.png (6.15 KiB) Viewed 5293 times

Post Reply

Return to “Keyboards”