• You are not logged in.
  • Index
  • Technical
  • Linux: How to change xkb's Level4 to CapsLock?

    Linux: How to change xkb's Level4 to CapsLock?

    • Started by mixer
    • 12 Replies:
    • Reputation: 1
    • Registered: 13-Nov-2018
    • Posts: 6

    Usually:
    - Level1 is normal keys.
    - Level2 is normal keys + Shift.
    - Level3 is AltGr.
    - Level4 is AltGr + Shift.

    What I would like to is to change Level4 to CapsLock, while keeping Level3=AltGr mapping.

    I know how to change Level5. I know how to change Level3 (even though I don't want to). But I can't find a way to disable the "Level4 = Level3 + Shift" mapping and change it to "Level4 = CapsLock". I even found a place ( /usr/share/X11/xkb/types ) where this kind of setting seems to be, but I can't make it work.

    I made CapsLock a Hyper key and tried to solve the problem through this approach, but didn't succeed either. I have spent enormous amount of time (literally working weeks), but I don't even know if I am wasting my time and this functionality is not possible to achieve (or is it and I just don't know how)...

    I would appreciate any help!

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

    You don't want to disable the level 4 mapping I think? Unless it actually bothers you that AltGr+Shift gives level 4, you can let it be.

    What you do want to do is to create a new modifier that is a level4 switch. We already have lvl12 (Shift), lvl3 (AltGr) and lvl5 (my Extend modifier for instance) switches. Then you can set your CapsLock key to that modifier. Your modifier needs to set both the AltGr(lvl+2) and Shift(lvl+1) states to achieve this.

    If AltGr+Shift = lvl4 does bother you, you'll have to create another modifier to select lvl3 while ignoring the Shift bit. I think that's doable too.

    Let me know how you fare with this! I actually need something similar but haven't gotten around to finishing it. My desired modifier activates lvl5+AltGr simultaneously so you can reach the second Extend layer on lvl7–8 with one key (and Shift) instead of the tortuous CapsLock+AltGr(+Shift) we have today.

    Last edited by DreymaR (15-Nov-2018 20:28:11)

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

    Offline
    • 0
    • Reputation: 15
    • Registered: 12-Sep-2016
    • Posts: 45

    You could try my program KLFC, which lets you create custom keyboard layouts. You can just take the example and change the following line in colemak.json

    "singletonKeys": [
      [ "CapsLock": "Backspace" ]
    ]

    to

    "singletonKeys": [
      [ "CapsLock": "shift:AltGr,Shift" ]
    ]

    You then can execute

    klfc colemak.json altgr_colemak.json --xkb xkb

    to create the XKB files in the folder xkb.

    Create advanced keyboard layouts in various formats using my Keyboard Layout Files Creator!

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

    What xkb code does that entry output, Aldo? Or, one with Level5 and AltGr?

    Last edited by DreymaR (15-Nov-2018 19:04:23)

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

    Offline
    • 0
    • Reputation: 1
    • Registered: 13-Nov-2018
    • Posts: 6

    It is so great to see you answer! I stumbled upon this forum while trying to find a solution to my problem and I was super-impressed by your work, your knowledge and your attitude! Thank you for making things that improve people's lives! Special thanks for consistency over the years!

    I haven't considered using Colemak yet (maybe in the future) and I am currently only interested in a functionality like your Extend layer provides. This is a system that is clearly very well though-out and is implemented on the level I have never seen before, not even close. This has been my inspiration so far before I saw what you did:
    1. http://tonsky.me/blog/cursor-keys/
    2. fUWu3Dn.png
    3. https://github.com/abogoyavlensky/keymap/
    keyboard-layout.png
    4. Plus Vim, obviously.

    DreymaR said:

    You don't want to disable the level 4 mapping I think? Unless it actually bothers you that AltGr+Shift gives level 4, you can let it be.

    The things that influenced my thinking were (please do tell if I am wrong in any of them; I am clearly not competent in this xkb subject):
    1. I am using two keyboard layouts (Finnish with some small changes; Russian phonetic created by me). I did that by editing appropriate files (like "fi" and "ru" files in "/usr/share/X11/xkb/symbols/" as well as adding them in a list of layouts. I know how to do that and am comfortable editing the files I know, in the way needed (I have already updated my OS and had no bigger trouble reapplying my keyboard changes. I would prefer the simplest way possible (making changes in 1 file is better than making changes in several files, like with creating custom layouts with groups and who knows how many changed files - I am not good at scripting and would have to understand everything first and then apply it manually)
    2. I am not really using Level4 symbols, but just in case it's better to leave the functionality as is if the particular Level4 key combination is not used.
    3. Obviously, for two languages I use, the Level1-4 symbols are different.
    4. AFAIK, it is not possible to just say "Ok, this group/layout will only define keys in Level4/5, while leaving everything else intact". AFAIK, if I want to use a certain key, I need to define (check here: http://domwatson.codes/2014/11/who-need … art-2.html ) all the levels ala "key <AC08> { [  k, K, kra, Down  ] };", even though Levels 1-3 have their own Symbols defined already and are dependent on the language used (for Finnish it is "k, K, kra", for Russian it is "Cyrillic_ka, Cyrillic_KA, kra,"). Maybe I am mistaken and there is a way to leave unwanted Levels+keys intact?
    5. Not all of the functionality I want can be defined in xkb. I would like to have the access to CapsLock so I can use it to start Autokey scripts (for example "clone the current line of text" turned out to be marvelous feature I am constantly using now). Currently I am defining CapsLock as Hyper key and it works well. I don't want to make changes to xkb that will lead me to losing this type of "greater scripting via Autokey" functionality.

    DreymaR said:

    What you do want to do is to create a new modifier that is a level4 switch. We already have lvl1 (Shift), lvl3 (AltGr) and lvl5 (my Extend modifier for instance) switches.

    Is there a typo(s)? Isn't Shift = lv2?

    DreymaR said:

    Then you can set your CapsLock key to that modifier. Your modifier needs to set both the lvl3 and lvl1 states to achieve this.

    I didn't understand the last sentence, please advise.


    I don't know if it helps, but here is my info:

    $ xmodmap -pm
    xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):
    
    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock      
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Meta_L (0xcd)
    mod2        Num_Lock (0x4d)
    mod3        Hyper_L (0xcf)
    mod4        Hyper_L (0x42),  Super_L (0x85),  Super_L (0xce)
    mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

    Your "Keyboard Tricks" are so far the best and closest thing I got to what I want. I think I will try to figure out what kind of changes you made in order to get Extend layers working. It's a pity that it is so closely integrated with Colemak layout (the one I don't want at the moment); and a double pity that I suck at scripting and it will be a big challenge to figure out the relevant parts I need...

    Thank you for everything you do (even if you won't be able to help me further - at least I know what to try next; this is a much better situation than simply being stuck).

    Last edited by mixer (15-Nov-2018 19:59:47)
    Offline
    • 0
    • Reputation: 214
    • From: Viken, Norway
    • Registered: 13-Dec-2006
    • Posts: 5,363

    Extend with XKB is quite tricky, as I had to define actions for many key states instead of just remapping those states like we normally do.

    Indeed, you can't use XKB to run programs or fancy stuff like that... directly. What you can do however, is map something to an unused key (of which there are many, such as many of the Multimedia keys) and then set that key as a hotkey to do what you want! In many Linux distros that's not hard to do; I only did it in Ubuntu where it's simple enough.

    Your cursor keys examples are typical of primitive Fn layers. What they haven't understood is the power of adding home row modifiers to the mix! Read my Extend topic to understand how much better that makes everything.

    I'm not sure if "Level1" is a name used for Shift anywhere else; it's usually just called "Shift". It may have been a bad name and "Level2" would be better. I think the modifier names suck because I think of Shift as "+1", AltGr as "+2" and Level5 as "+4" bitwise! Anyway, you're right: Shift indeed brings you to Level2. :-) I edited the previous post for clarity.

    There is a way of leaving some levels intact while mapping others! See how I did it at the end of the Greek layout file (symbols/gr) for instance.

    Last edited by DreymaR (15-Nov-2018 20:32:57)

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

    Offline
    • 0
    • Reputation: 15
    • Registered: 12-Sep-2016
    • Posts: 45
    DreymaR said:

    What xkb code does that entry output, Aldo? Or, one with Level5 and AltGr?

    It will assign AltGr and Shift to Caps Lock like this

    key <CAPS> { [ ISO_Level3_Shift ],
                 actions[Group1] = [ SetMods(mods=LevelThree+Shift) ],
                 vmods=LevelThree };
    modifier_map Mod5 { ISO_Level3_Shift };

    But I think the vmods and modifier_map aren't necessary when AltGr on Alt_R is already defined.

    Create advanced keyboard layouts in various formats using my Keyboard Layout Files Creator!

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

    Thanks, Aldo! I had supposed that it'd be trickier, having to define a modifier. But I see that I was overthinking the issue. ^_^

    This way, one could even define a layer lock key with the LockMods() action I think, and one-shot with LatchMods()?

    So...

    key <RCTL> { [ ISO_Level5_Shift ], actions[Group1] = [ SetMods(mods=LevelThree+LevelFive) ] };
    modifier_map Mod3   { ISO_Level5_Shift };

    That look right?

    Last edited by DreymaR (19-Nov-2018 09:55:19)

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

    Offline
    • 0
    • Reputation: 1
    • Registered: 13-Nov-2018
    • Posts: 6

    Thank you DreymaR and 39aldo39 for help!

    In the end I decided to leave level4 as is and just adopt DreymaR's Extend layout.

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

    Hope it serves you well! Let us know how you fare. And read the Extend topic in the Big Bag for nifty tips. ^_^

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

    Offline
    • 0
    • Reputation: 117
    • From: UK
    • Registered: 14-Apr-2014
    • Posts: 978
    mixer said:

    In the end I decided to leave level4 as is and just adopt DreymaR's Extend layout.

    Very wise, on a standard keyboard it's easily your best bet the others you listed don't have home-row modifiers.

    What are you using as your Extend key?

    Using Colemak-DH with Seniply.

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

    I've forgotten which keys are available for lvl5 modifiers out-of-the-box; I only added the Caps switch. Using the formalism Aldo describes one could map any key level to the Extend/lvl5 modifier, so that's a possibility. Or check out my caps_switch_lock code and modify it to another key as a dirty trick. ;-)

    Last edited by DreymaR (14-Dec-2018 09:48:44)

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

    Offline
    • 0
    • Reputation: 1
    • Registered: 13-Nov-2018
    • Posts: 6
    DreymaR said:

    Hope it serves you well! Let us know how you fare. And read the Extend topic in the Big Bag for nifty tips. ^_^

    Oh, you have no idea how much time I have spent been reading it... :) I will write a post with feedback and questions in there in upcoming days.


    stevep99 said:

    What are you using as your Extend key?

    Caps.

    Last edited by mixer (13-Dec-2018 20:47:49)
    Offline
    • 0
      • Index
      • Technical
      • Linux: How to change xkb's Level4 to CapsLock?