LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Changing non-printing keys in keyboard layout (https://www.linuxquestions.org/questions/linux-general-1/changing-non-printing-keys-in-keyboard-layout-879670/)

dotancohen 05-09-2011 11:14 AM

Changing non-printing keys in keyboard layout
 
Hi all, I'm trying to write a new keyboard layout. I'm testing using Debian Squeeze and Kubuntu 11.04, both with KDE. It is important to solve this issue with a keyboard layout as opposed to playing with xmodmap or scancodes and keycodes because I need to leave other keyboard layouts intact and usable. For the time being the new layout is called Noah, implemented as a variant of US English. If this is done more easily by making whole new layout that is not a variant of another then I am willing to go that route.

First off, I am trying to move the Caps Lock key to the current location of the "B" Key. This is my code (the unshown parts of the files have not been touched):
Code:

✈demios:~$ tail /usr/share/X11/xkb/symbols/us -n 68
xkb_symbols "noah" {
 name[Group1]= "USA - Noah Ergonomic";
 include "pc(noah)"
  key <TLDE> { [ 5,            percent    ] };
  key <AE01> { [ 4,            dollar      ] };
  key <AE02> { [ 3,            numbersign  ] };
  key <AE03> { [ 2,            at          ] };
  key <AE04> { [ 1,            exclam      ] };
  key <AE05> { [ Escape                    ] };
  key <AE06> { [ grave,        asciitilde  ] };
  key <AE07> { [ minus,        underscore  ] };
  key <AE08> { [ equal,        plus        ] };
  key <AE09> { [ 6,            asciicircum ] };
  key <AE10> { [ 7,            ampersand  ] };
  key <AE11> { [ 8,            asterisk    ] };
  key <AE12> { [ 9,            parenleft  ] };
  key <BKSP> { [ 0,            parenright  ] };

  key <TAB>  { [ q,            Q          ] };
  key <AD01> { [ w,            W          ] };
  key <AD02> { [ e,            E          ] };
  key <AD03> { [ r,            R          ] };
  key <AD04> { [ t,            T          ] };
  key <AD05> { [ Tab,          Tab        ] };
  key <AD06> { [ bracketleft,  braceleft  ] };
  key <AD07> { [ bracketright,  braceright  ] };
  key <AD08> { [ y,            Y          ] };
  key <AD09> { [ u,            U          ] };
  key <AD10> { [ i,            I          ] };
  key <AD11> { [ o,            O          ] };
  key <AD12> { [ p,            P          ] };
  key <BKSL> { [ slash,        question    ] };

  key <CAPS> { [ a,            A          ] };
  key <AC01> { [ s,            S          ] };
  key <AC02> { [ d,            D          ] };
  key <AC03> { [ f,            F          ] };
  key <AC04> { [ g,            G          ] };
  key <AC05> { [ Return                    ] };
  key <AC06> { [ apostrophe,    quotedbl    ] };
  key <AC07> { [ Return                    ] };
  key <AC08> { [ h,            H          ] };
  key <AC09> { [ j,            J          ] };
  key <AC10> { [ k,            K          ] };
  key <AC11> { [ l,            L          ] };
  key <RTRN> { [ semicolon,    colon      ] };

  key <LFSH> { [ z,            Z          ] };
  key <AB01> { [ x,            X          ] };
  key <AB02> { [ c,            C          ] };
  key <AB03> { [ v,            V          ] };
  key <AB04> { [ b,            B          ] };
  key <AB05> { [ Backspace,    Caps_Lock  ] };
  key <AB06> { [ Super_L,      Super_R    ] };//test these
  key <AB07> { [ backslash,    bar        ] };
  key <AB08> { [ n,            N          ] };
  key <AB09> { [ m,            M          ] };
  key <AB10> { [ comma,        less        ] };
  key <RTSH> { [ period,        greater    ] };

  key <LCTL> { [ Control_L                  ] };
  key <LWIN> { [ Alt_L                      ] };
  key <LALT> { [ Shift_L                    ] };
  key <SPCE> { [ space                      ] };
  key <RALT> { [ Shift_R                    ] };
  key <RWIN> { [ Alt_R                      ] };//test this
  key <RCTL> { [ Control_R                  ] };
};
✈demios:~$

Code:

✈demios:~$ tail /usr/share/X11/xkb/symbols/pc -n 4
partial  modifier_keys
xkb_symbols "noah" {
 modifier_map Lock { <AB05> };
};
✈demios:~$

The problem is that this configuration is also affecting the US English layout. When I press "B" the keyboard gives a B _and_ a Caps Lock! So typing I get output like this: "keybOARD". How do I restrict the B key to being Caps Lock only in the Noah layout?

Here is the homepage of the Noah layout:
http://dotancohen.com/eng/noah_ergon...rd_layout.html

Thanks!

DavidMcCann 05-09-2011 11:45 AM

The file /usr/share/X11/xkb/symbols/pc will affect everything, because it is included when compiling all layouts. Leave it to show
modifier_map Lock { Caps_Lock, ISO_Lock };

The key <AB05> will be translated to Caps_Lock by
key <AB05> { [ Backspace, Caps_Lock ] };
All the line in the other file does is to define what Caps_Lock does.

dotancohen 05-09-2011 11:51 AM

Thanks, David. However, I need to place the "A" key in Noah where the current Caps Lock is, so how can I make the Lock key stop being Caps_Lock when the Noah layout is in use?

As it stands, when I press "A" in the Noah layout it activates the letter "A" _and_ Caps_Lock. Noah "A" is on the QWERTY Caps_Lock key.

DavidMcCann 05-10-2011 11:24 AM

The problem here is that <CAPS> is being defined as Caps_Lock by the file …/symbols/pc and also by …/symbols/capslock.

You need to start again with a different approach by editing
/usr/share/X11/xkb/keycodes/evdev
Replace
<CAPS> = 66;
<AB05> = 56;
with
<AC00> = 66;
<CAPS> = 56;
Then all the references to <CAPS> in the original symbols files can be left alone and you will only need to set
key <AC00> { [ a, A ] };

dotancohen 05-10-2011 01:23 PM

Thanks, David, but that would prevent Caps_Lock from working properly in the standard US English QWERTY variant!

Could I make a new file /usr/share/X11/xkb/keycodes/evdev-noah which would have the proper code set like this:
<AC00> = 66;
<CAPS> = 56;

And then in the Noah variant I would use the evdev-noah file instead of evdev? How would I call the evdev-noah file then?

If this is not possible, then could it be done if Noah were a different layout, as opposed to being a US English variant?

Thanks.

DavidMcCann 05-11-2011 10:42 AM

I didn't realise that you were still using the standard layout as well. In that case you will have to keep the evdev file untouched and create a separate symbols file noah. You can incorporate the contents of the pc and capslock files into that, replacing all references to CAPS with AB05.

If that doesn't work, then something will have been calling the pc or capslock files. The command
setxkbmap -print
will show all the material used to create the drivers, so you can check the types and compat files listed, and the ones they call.

Your keyboard installer will probably list available keyboards by language and country, so "noah" will not appear. You can add it manually: on my Fedora computer it's in
~/.gconf/desktop/gnome/peripherals/keyboard/kbd/%gconf.xml
where I have the special keyboard astro enabled:
<entry name="layouts" mtime="1298041593" type="list" ltype="string">
<li type="string">
<stringvalue>gb</stringvalue>
</li>
<li type="string">
<stringvalue>gr</stringvalue>
</li>
<li type="string">
<stringvalue>astro</stringvalue>
</li>
</entry>

dotancohen 05-11-2011 03:28 PM

Thanks, David, I just spend a few hours tracking things down through "setxkbmap -print". That was a great tip, I cannot thank you enough!

It seems that I could simply reassign keycodes from aliases in /usr/share/X11/xkb/keycodes/evdev like you suggested earlier, but instead of saving them to that file I would save them to a new file, say, /usr/share/X11/xkb/keycodes/evdev-noah. But how do I call that file from the Noah layout? What does the word "evdev" stand for, this might be hint!

I'm not really sure how things get called, and so I'm stuck. If I create a new layout (not a variant as I have been doing) then I make a new file /usr/share/X11/xkb/symbols/noah using /usr/share/X11/xkb/symbols/us as a template:
Code:

default
partial alphanumeric_keys modifier_keys
xkb_symbols "basic" {
    key <CAPS> { [ b, B      ] };
    key <AB05> { [ Caps_Lock  ] };
};

Here I'm simply swapping Caps_Lock and "B". What do the declarations "partial" "alphanumeric_keys" "modifier_keys" actually do? How do I call /usr/share/X11/xkb/keycodes/evdev-noah instead of having it call the regular evdev file? What _is_ the airspeed velocity of an unladen swallow?

There are tons of resources online for creating custom layouts, but nothing addresses the modifier keys or Caps. I'm pretty certain if we can swap Caps_Lock and B then I can figure the rest out. Your help is cordially appreciated.

DavidMcCann 05-12-2011 11:18 AM

I think I've reached my limits here too! On my keyboard, the old Caps is now Third level shift, old Scroll lock is Group shift, and old Pause is Caps, but this applied to all my keyboard drivers, so I don't have your problem.

The markup in these tables is very obscure. Sections can include references to modifiers without being marked as doing so (and vice versa!) and "partial" is a bit of a mystery too.

The whole process starts when the computer finds a PC (as opposed to Mac or Sun) keyboard and takes evdev for the list of keycodes (unless the distro prefers xfree86). In other words, by the time you log in and it sees what drivers you want, it's too late to change. That's why you can only have one version of evdev.

dotancohen 05-13-2011 07:18 AM

Quote:

Originally Posted by DavidMcCann (Post 4354454)
I think I've reached my limits here too! On my keyboard, the old Caps is now Third level shift, old Scroll lock is Group shift, and old Pause is Caps, but this applied to all my keyboard drivers, so I don't have your problem.

Nice! I also intend to move Caps off to the scroll lock or pause position in the end on this layout. We are similarly fastidious apparently.

Quote:

The markup in these tables is very obscure. Sections can include references to modifiers without being marked as doing so (and vice versa!)
Really?!? That seems to be my issue, as even right there in the stock us(basic) layout there are no include statements. I assumed that the "partial" bit means that it will include something marked as filling in for partial, and maybe the alphanumeric_keys and modifier_keys do something similar. I just don't know, and I don't see it documented anywhere.

Quote:

and "partial" is a bit of a mystery too.
Yes.

Quote:

The whole process starts when the computer finds a PC (as opposed to Mac or Sun) keyboard and takes evdev for the list of keycodes (unless the distro prefers xfree86). In other words, by the time you log in and it sees what drivers you want, it's too late to change. That's why you can only have one version of evdev.
Ah, I see. Thanks. I wonder if any of the CJK or other Asian language keyboards have varied modifier keys, I'll look around and hopefully find something. I'll update the thread if so.

Thanks!

fui.de.recife 12-25-2021 04:25 PM

The treasure trove these old threads are
 
10 years later is a long time. However, when looking for any solution for the puzzle of trying to map Caps Lock to a normal key, this discussion was the only guiding light I've found. And what a help it was! So I want to thank both dotancohen and DavidMcCann for their help.

Since what I wanted was to make the Caps key to behave as a level 1 key, DavidMcCann showed me the way in this thread's #4 post. It's as simple as he describes there. You just assign the Caps keycode to a new label (AC00, for example, as he suggested), and change the CAPS keycode to another key, existing or not.

In my case, I pointed the CAPS label to the keycode of a special key I never use on my keyboard. I then created that new AC00 label with the Caps key actual keycode. Then, on my layout file, I defined what characters I wanted printed upon using that AC00 key. Then I saved the file, restarted my X session and, voilá, the magic happened.

So if anyone is looking for something similar, you have to look no further than to this thread. And if both participants are still out there and come across my post, thank you so much for your help. It's exchanges like this that make the internet such a wonderful tool.

DavidMcCann 12-26-2021 11:11 AM

Thank you! It's always nice to think that old posts are still doing their job. That's what makes a forum a great place, as opposed to something like a mailing list or (worse) reddit.


All times are GMT -5. The time now is 05:34 PM.