• You are not logged in.

    How to "hard keymap" under Linux?

    • Started by makdhfan
    • 12 Replies:
    • Reputation: 0
    • Registered: 25-Jan-2020
    • Posts: 7

    tldr; How to map qwerty keyboard signals to mod-dh that works everywhere. i.e. console, x, input methods without modifying the hardware keyboard under Linux?

    Hi, I'm huge fan of the colemak mod-dh layout, and have been using it exclusively under Windows for years now. Under Windows, I used a program called "keymapper" to make my qwerty keyboard function like a mod-dh one via Windows Registry. It's the same as a privileged autohotkey map script. I needed to type a lot of different languages, some of them require an "input method". Via Windows Registry, I can use mod-dh without the need to configure anything else while typing in other languages. I'm looking for help on how to do something similar to this under Linux. Thank you.

    Last edited by makdhfan (25-Jan-2020 21:11:21)
    Offline
    • 0
    • Reputation: 117
    • From: UK
    • Registered: 14-Apr-2014
    • Posts: 978

    I'm guessing when you say the console, you are talking about when X is not loaded, and therefore DreymaR's xkb scripts won't work in this scenario. To get around this problem, I did create some basic console remapping scripts some time ago, which are here.

    In fairness, I guess you would have the analogous issue in Windows too - for example, presumably your Windows Registry changes are only effective once Windows has loaded, and if you tried to use the old DOS-style console outside Windows (if that is even still possible?), then I'd assume you'd get the same problem of the mappings not taking effect.

    I don't know of a solution where you can set the mappings in one place and it would work in both console and GUI.  But it seems a fair criticism - keyboards are fundamentally a low level thing, so you'd think being able to do it that way would make sense.

    Using Colemak-DH with Seniply.

    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,361

    In Windows, you can't run a command line underneath the OS anymore, not since... Windows NT or 2000? And the registry remappings are so low level that they'll work anywhere.

    So yeah, this problem is a pretty Linux specific one. Without XKB you can't do the advanced things I like, so xmodmap alone is not an acceptable solution. But for the terminal consoles I guess you may need it.

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Online
    • 0
    • Reputation: 0
    • Registered: 25-Jan-2020
    • Posts: 7

    @Stevep99, thank you. You are right. Indeed as long as the Windows is not yet loaded, the mapping won't take effect. It's only doing things on the software side after all. It is, however, low level enough to trick everything that runs inside Windows. That's what I wanted to make happen with Linux, to trick every program that runs inside of the current Linux instance.

    @DreymaR, thank you.

    If a way to trick a whole Linux instance not feasible right now, can it be done just for X? I just reinstalled Windows back because I couldn't make it work and I have to type with input methods.

    The issue with most input methods is that they're designed with a qwerty layout. In Windows, I can trick them all with Registry, and type in any language with mod-dh. I hope I can do this in Linux someday soon.

    Offline
    • 0
    • Reputation: 0
    • Registered: 25-Jan-2020
    • Posts: 7
    stevep99 said:

    I'm guessing when you say the console, you are talking about when X is not loaded, and therefore DreymaR's xkb scripts won't work in this scenario. To get around this problem, I did create some basic console remapping scripts some time ago, which are here.

    In fairness, I guess you would have the analogous issue in Windows too - for example, presumably your Windows Registry changes are only effective once Windows has loaded, and if you tried to use the old DOS-style console outside Windows (if that is even still possible?), then I'd assume you'd get the same problem of the mappings not taking effect.

    I don't know of a solution where you can set the mappings in one place and it would work in both console and GUI.  But it seems a fair criticism - keyboards are fundamentally a low level thing, so you'd think being able to do it that way would make sense.

    Colemak mod-dh is marvelously good. I use it to type everything. Thank you for that.

    I was looking at your Extend Layer AutoHotkey scripts, and was wondering how can I change the toggle key from capslock to space, but can still issue a space with "space down and then up without key presses in between", like touchcursor? My autohotkey knowledge is limited. It'd be great if you could kindly point me the direction. Thank you. :)

    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,361

    If it's in Windows you want to do this, EPKL should support it through the "Tap-or-Mod" key type. But myself, I'd be wary of using it on such a common key as Space. But let me know if it works well.

    What you need to do then, is remove the Capslock mapping and add a mapping line in your chosen layout.ini, like this:

    SC039 = SPACE/Ext  VKey

    It's also possible to get more fancy and use the Extend taps differently depending on shift state when tapping it. That's what I do, the "Mother of Dead Keys" key.

    Last edited by DreymaR (27-Jan-2020 12:38:38)

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Online
    • 0
    • Reputation: 117
    • From: UK
    • Registered: 14-Apr-2014
    • Posts: 978

    Glad DH is working for you!  My AutoHotkey scripts don't support dual-role modifiers, but I have seen this done in other AHK scripts so I believe it is possible. I'm not an AHK expert either, and anyway am mostly using Linux these days, so can only recommend looking up other sources. Or use EPKL as DreymaR says.

    Mind you, when I have experimented previously with dual-mode space, I found that it doesn't work very smoothly once your typing reaches a certain speed as you tend to hit space then the subsequent letter quickly enough that the key-up and key-down events are not necessarily in the right order. So personally I am skeptical of this approach and prefer dedicated keys for important keys like Space and Extend. Dual-mode might be OK for lesser used keys though.

    Last edited by stevep99 (27-Jan-2020 15:02:00)

    Using Colemak-DH with Seniply.

    Offline
    • 0
    • Reputation: 0
    • Registered: 25-Jan-2020
    • Posts: 7

    @stevep99 @DreymaR I'm very grateful. All the information you provided are helpful. I'll look into all these tips and see how it goes. Thank you very much for taking the time. My story with Linux as main isn't over! I'll try again in probably a few years.

    Last edited by makdhfan (28-Jan-2020 15:45:55)
    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,361

    @stevep99 To use Tap-or-Mod keys, you have to use timers and key interrupt routines so that if you type something else before releasing the ToM key it'll be interpreted as a tap not a wait unless the timer is up in which case it'll be a modified stroke instead. I took a page from the TMK code to see the importance of this. Even so, I haven't managed to make those fancy ToM keys on S/T & N/E (LShift/LCtrl & RCtrl/RShift) that I saw someone on the Discord use. At high speed, the key sequence got jumbled as you say. One challenge is that you expect a Shift to take very quickly so you can't have anywhere near a generous timer for it (and you can't use Sticky Shift on a ToM, obviously). In contrast, I've hardly had any trouble at all with the Caps key as ToM Mother-of-DeadKeys / Extend.

    Last edited by DreymaR (29-Jan-2020 11:12:17)

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Online
    • 0
    • Reputation: 117
    • From: UK
    • Registered: 14-Apr-2014
    • Posts: 978
    DreymaR said:

    @stevep99 To use Tap-or-Mod keys, you have to use timers and key interrupt routines so that if you type something else before releasing the ToM key it'll be interpreted as a tap not a wait unless the timer is up in which case it'll be a modified stroke instead. I took a page from the TMK code to see the importance of this. Even so, I haven't managed to make those fancy ToM keys on S/T & N/E (LShift/LCtrl & RCtrl/RShift) that I saw someone on the Discord use. At high speed, the key sequence got jumbled as you say. One challenge is that you expect a Shift to take very quickly so you can't have anywhere near a generous timer for it (and you can't use Sticky Shift on a ToM, obviously). In contrast, I've hardly had any trouble at all with the Caps key as ToM Mother-of-DeadKeys / Extend.

    That's interesting. Even at the time I remember thinking if the timing could be set right, it might be possible to get it to work. If there were a way to do this cross-platform - i.e. a xkb-compatible method - then I'd be interested in revisiting this idea.

    Last edited by stevep99 (30-Jan-2020 16:02:26)

    Using Colemak-DH with Seniply.

    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,361

    Seems to me that the QMK/TMK people have cracked this problem, so I guess we'll have to ask them how it can be done robustly. Dusty at the Discord uses home row tap-or-mod keys, and he finds them great it seems.

    *** Learn Colemak in 2–5 steps with Tarmak! ***
    *** Check out my Big Bag of Keyboard Tricks for Win/Linux/TMK... ***

    Online
    • 0
    • Reputation: 18
    • From: CZ
    • Registered: 14-Feb-2012
    • Posts: 444

    Keyboards send low-level scancodes to the host system. Linux kernel translates scancodes to keycodes (later used by XKB and others). You can create your own scancode:keycode mapping in /etc/udev/hwdb.d/.

    Dual-role keys for SpaceFN have been implemented as Xorg input driver; there's TouchCursor clone and KMonad might work too.

    Get yourself an ergonomic keyboard. Learn Maltron. Or stenography.

    Offline
    • 1
    • Reputation: 117
    • From: UK
    • Registered: 14-Apr-2014
    • Posts: 978

    Some interesting projects there. I even cloned touchcursor-linux to try it out and it worked! However as far as I can tell, there's no clever timer-based configuration as per DreymaR's mentionings. It's also interesting that you can select by specific keyboard name if you have more than one connected.  Coincidentally I came across this video recently, where this would have solved his problem, but he mentions specifically about not using linux about half way through.

    Last edited by stevep99 (09-Mar-2020 17:31:25)

    Using Colemak-DH with Seniply.

    Offline
    • 0