Kolja
Kolja

Reputation: 2759

How do I produce a German umlaut with KMK

I am making a custom keyboard with KMK / MicroPython on a Raspberry Pi Pico to be used with OSX.

I would like it to have convenient access to German umlauts (äÄöÖüÜ), so I defined a dedicated KC.UMLAUT key, which, when pressed together with A, O, or U should produce the corresponding umlaut. When shift is pressed too, it should send the capitalized version.

Here is what I have:

import board

from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC, make_key
from kmk.handlers.sequences import simple_key_sequence
from kmk.modules.combos import Combos, Sequence

keyboard = KMKKeyboard()

AUML = simple_key_sequence( ( KC.LALT(KC.U), KC.A,))
AUML_CAP = simple_key_sequence( ( KC.LALT(KC.U), KC.RSFT(KC.A),))

make_key(
    KC.NO.code,
    names=(
        'UMLAUT',
    )
)

combos = Combos()
combos.combos = [
    Sequence((KC.UMLAUT, KC.A), AUML),
    Sequence((KC.UMLAUT, KC.RSFT, KC.A), AUML_CAP),
    # ... I also have Sequences for O and U
]

keyboard.keymap = [
    [
        KC.A, KC.O, KC.U, 
        KC.UMLAUT, KC.RSFT,
    ]
]

if __name__ == "__main__":
    keyboard.go()

However, this approach is flawed in many ways:

Only the first press of umlaut-A produces an "ä" character. Subsequent presses (with umlaut held down) give a regular "a" again. Also, umlaut and shift have to be pressed in that order -- shift-umlaut-A won't work.

Last but not least, I don't like how I need separate definitions for the shifted behavior. It feels like I am on the wrong track here. Surely there is a better (and less verbose) way to do such a basic thing?

Upvotes: 1

Views: 429

Answers (2)

Kolja
Kolja

Reputation: 2759

This is what I am living with (for now):

import board

from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.modules.holdtap import HoldTap
holdtap = HoldTap()

# tap => ¨, hold => KC.LALT
LALT = KC.HT(KC.LALT(KC.U), KC.LALT)

keyboard.modules.append(holdtap)

Holding down the key lets it act as regular alt key (so 'ß' still works). Tapping it followed by any of aouAOU renders the corresponding umlaut.

This doesn't quite answer my original question. It's the compromise I've settled for.

Upvotes: 0

David Pham
David Pham

Reputation: 1

The solution I found for myself was to use the US International Keyboard Layout which offers german Umlaute with the following shortcuts:

  • Right-Alt + Q = ä
  • Right-Alt + Y = ü
  • Right-Alt + P = ö

Using this I've created the following combos:

combos.combos = [
    Chord((KC.A, KC.S), KC.RALT(KC.Q), timeout=30),
    Chord((KC.S, KC.D), KC.RALT(KC.S), timeout=30),
    Chord((KC.U, KC.I), KC.RALT(KC.Y), timeout=30),
    Chord((KC.O, KC.P), KC.RALT(KC.P), timeout=30),
]

This solution works in combination with the SHIFT modifier as well.

There is probably another way by using make_key() to create custom keys.

Upvotes: 0

Related Questions