xkb 重映射对某些键不起作用

xkb 重映射对某些键不起作用

Delete我正在尝试使用 xkb 重新映射一些键。在下面的摘录中,我更改了两行来配置我的键映射。空格键工作正常。但我映射的两个键都BKSP不起作用,而 BackSpace 和 AltGr+BKSP=BackSpace 可以正常工作。

我想使用Backspace+Shift作为Delete

我的 /usr/share/X11/xkb/symbols/pc文件如下所示:

default  partial alphanumeric_keys modifier_keys
xkb_symbols "pc105" {

    key <ESC>  {    [ Escape        ]   };

    // The extra key on many European keyboards:
    key <LSGT> {    [ less, greater, bar, brokenbar ] };

    // The following keys are common to all layouts.
    key <BKSL> {    [ backslash,    bar ]   };
//    key <SPCE> {  [    space      ]   };
// user manipulated next line. this works and has nothing to do with my question.
    key <SPCE> {      [ space, space, bar       ]       };
    include "srvr_ctrl(fkey2vt)"
    include "pc(editing)"
    include "keypad(x11)"

//    key <BKSP> {  [ BackSpace, BackSpace  ]   };
// user manipulated next line. This does not work and is relevant for this question.
    key <BKSP> {        [ BackSpace,  Delete,  BackSpace, Delete ]   };

    key  <TAB> {    [ Tab,  ISO_Left_Tab    ]   };
    key <RTRN> {    [ Return        ]   };

    key <CAPS> {    [ Caps_Lock     ]   };
    key <NMLK> {    [ Num_Lock      ]   };

    key <LFSH> {    [ Shift_L       ]   };
    key <LCTL> {    [ Control_L     ]   };
    key <LWIN> {    [ Super_L       ]   };

    key <RTSH> {    [ Shift_R       ]   };
    key <RCTL> {    [ Control_R     ]   };
    key <RWIN> {    [ Super_R       ]   };
    key <MENU> {    [ Menu          ]   };

    // Beginning of modifier mappings.
    modifier_map Shift  { Shift_L, Shift_R };
    modifier_map Lock   { Caps_Lock };
    modifier_map Control{ Control_L, Control_R };
    modifier_map Mod2   { Num_Lock };
    modifier_map Mod4   { Super_L, Super_R };

    // Fake keys for virtual<->real modifiers mapping:
    key <LVL3> {    [ ISO_Level3_Shift  ]   };
    key <MDSW> {    [ Mode_switch       ]   };
    modifier_map Mod5   { <LVL3>, <MDSW> };

    key <ALT>  {    [ NoSymbol, Alt_L   ]   };
    include "altwin(meta_alt)"

    key <META> {    [ NoSymbol, Meta_L  ]   };
    modifier_map Mod1   { <META> };

    key <SUPR> {    [ NoSymbol, Super_L ]   };
    modifier_map Mod4   { <SUPR> };

    key <HYPR> {    [ NoSymbol, Hyper_L ]   };
    modifier_map Mod4   { <HYPR> };
    // End of modifier mappings.

    key <OUTP> { [ XF86Display ] };
    key <KITG> { [ XF86KbdLightOnOff ] };
    key <KIDN> { [ XF86KbdBrightnessDown ] };
    key <KIUP> { [ XF86KbdBrightnessUp ] };
};

hidden partial alphanumeric_keys
xkb_symbols "editing" {
    key <PRSC> {
    type= "PC_ALT_LEVEL2",
    symbols[Group1]= [ Print, Sys_Req ]
    };
    key <SCLK> {    [  Scroll_Lock      ]   };
    key <PAUS> {
    type= "PC_CONTROL_LEVEL2",
    symbols[Group1]= [ Pause, Break ]
    };
    key  <INS> {    [  Insert       ]   };
    key <HOME> {    [  Home         ]   };
    key <PGUP> {    [  Prior        ]   };
    key <DELE> {    [  Delete       ]   };
    key  <END> {    [  End          ]   };
    key <PGDN> {    [  Next         ]   };

    key   <UP> {    [  Up           ]   };
    key <LEFT> {    [  Left         ]   };
    key <DOWN> {    [  Down         ]   };
    key <RGHT> {    [  Right        ]   };
};

输出setxkbmap -print

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwertz)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+de+gr(extended):2+ru(dos):3+us:4+inet(evdev)+ctrl(nocaps)+terminate(ctrl_alt_bksp)" };
    xkb_geometry  { include "pc(pc105)" };
};

xev 输出:

KeyPress event, serial 37, synthetic NO, window 0x6a00001,
    root 0x13d, subw 0x0, time 2108465, (124,40), root:(1315,695),
    state 0x10, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 37, synthetic NO, window 0x6a00001,
    root 0x13d, subw 0x0, time 2108612, (124,40), root:(1315,695),
    state 0x11, keycode 22 (keysym 0xffff, Delete), same_screen YES,
    XKeysymToKeycode returns keycode: 119
    XLookupString gives 1 bytes: (7f) ""
    XmbLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x6a00001,
    root 0x13d, subw 0x0, time 2108707, (124,40), root:(1315,695),
    state 0x11, keycode 22 (keysym 0xffff, Delete), same_screen YES,
    XKeysymToKeycode returns keycode: 119
    XLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x6a00001,
    root 0x13d, subw 0x0, time 2108764, (124,40), root:(1315,695),
    state 0x11, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

现在,通过我所做的操作,按Backspace+Shift会给我一个~。我正在使用 X11 并在德语和美国布局之间切换。

答案1

我通常不喜欢说原帖作者的意图是否正确。无论如何,不​​建议编辑这些标准符号文件(例如pc、、等),因为它们可能会在系统更新中被覆盖。但是,更改这些文件更de容易us,因为它们要么同时影响多个布局,要么这些布局已经可以在 gnome-settings(或其他常用位置)中选择。相反,如果您从头开始创建自定义布局,则必须更改其他一些文件才能在设置中找到这些布局。(或者您需要使用来设置键盘布局setxkbmap

无论如何,我不确定为什么 BKSP 会返回~。(在哪个应用程序中它会返回波浪符号?这些 xkb 自定义并不总是被所有应用程序平等地解释)。也许 BKSP 在构成键盘布局的其他一些符号文件中被重新定义。无论如何,我相信以下内容可以解决您的问题。您有(至少)两个选项,一个更难但“更安全”或一个更简单但“持续时间较短”。我会给出一个“偏执”的答案,但当然,您可以获取相关信息并按照您认为最好的方式去做。

创建自定义符号文件

我将其命名为。如果您将其命名为其他名称,请确保它与定义文件中的语句custom一致。includes

此文件可以在所有其他符号定义(针对其他语言和布局)所在的位置找到/usr/share/X11/xkb/symbols/。由于编辑文件夹外的文件是不好的做法home,因此请在某个可以编辑和链接的文件处创建一个文件/usr/share/X11/xkb/symbols

cd <PATH-WHERE-YOUR-SYBMBOLS-FILE-IS>
sudo ln -sr ./custom /usr/share/X11/xkb/symbols/

的内容custom

SHIFT使+正常运行的相关部分BackSpace如下所示。请注意clearmods=Shift选项。

partial alphanumeric_keys xkb_symbols "backspace_delete" {
    key.type[Group1] = "TWO_LEVEL";
    key <BKSP> { 
            symbols[Group1] = [ BackSpace, Delete], 
            actions[Group1] = [ NoAction(), RedirectKey(keycode=<DELE>, clearmods=Shift) ]
    };
};

其余的.../符号/自定义:

default partial alphanumeric_keys xkb_symbols "basic" {

    name[Group1]="German Custom";

    // basic layout 
    include "de(basic)" // you could also include "de(deadgraveacute)" if you are not using the plain german layout

    // special includes (these can be also choosen from gnome tweaks > additional layout options)
    include "ctrl(nocaps)"  
    include "terminate(ctrl_alt_bksp)"
    include "level3(ralt_switch)" // <<-- adapt accordingly (possible pre-made definitions in /usr/share/X11/symbols/level3)

    // custom includes
    include "custom(backspace_delete)"
    include "custom(other_changes)"

};

default alphanumeric_keys partial  xkb_symbols "us" {

    name[Group1]="US Custom";

    // basic layout 
    include "us(basic)"

    // special includes 
    include "ctrl(nocaps)"  
    include "terminate(ctrl_alt_bksp)"
    include "level3(ralt_switch)" // <<-- adapt accordingly (possible pre-made definitions in /usr/share/X11/symbols/level3)

    // custom includes
    include "custom(backspace_delete)"
    include "custom(other_changes)"
}; 


partial alphanumeric_keys xkb_symbols "backspace_delete" {
    key.type[Group1] = "TWO_LEVEL";
    key <BKSP> { 
            symbols[Group1] = [ BackSpace, Delete], 
            actions[Group1] = [ NoAction(), RedirectKey(keycode=<DELE>, clearmods=Shift) ]
    };
};

partial alphanumeric_keys xkb_symbols "other_changes" {
    key <SPCE> { [ space,       space,        bar,       NoSymbol     ] };  // NoSymbol does not override previous definition, VoidSymbol does.
};

为了在 gnome 设置中找到您的自定义布局,请修改/usr/share/X11/xkb/rules/evdev.xml。这是一个很长的 xml 文件,请将其插入该文件中的某个位置。(这里我不确定我是否可以在任何地方,或者您是否应该在德语部分下引入一部分,在美国部分下引入另一部分。)

    <!-- Keyboard indicator for Custom Layouts -->
    <layout>
      <configItem>
        <name>custom</name>
        <shortDescription>cu</shortDescription>
        <description>Custom (German - base)</description>
        <languageList>
          <iso639Id>ger</iso639Id>
        </languageList>
      </configItem>
      <variantList>
        <variant>
          <configItem>
            <name>us</name>
           <description>Custom (US)</description>
          </configItem>
        </variant>
      </variantList>
    </layout>
    <!-- End of Custom Layouts -->
  • 您可能需要运行sudo dpkg-reconfigure xkb-data才能在设置中显示自定义键盘。
  • 在试用布局时,您可以运行setxkbmap custom基础版(德语)或setxkbmap custom -variant us美国版本。
  • 如果您仍然希望直接编辑pc文件,我建议您通过以下方式进行操作:1) 创建一个或多个partial定义,并且只创建或相关定义中的include定义。为此,您只需将文件放在 xkb/symbols 文件夹中并相应地使用即可。pcdeuscustominclude "nameOfFile(nameOfPartial)"

相关内容