XKB:Shift 或 Control + 数字键盘 = 向下,不带 Shift

XKB:Shift 或 Control + 数字键盘 = 向下,不带 Shift

我想映射我的键盘,以便(当 Numlock 打开时),2名为2 的数字键盘键KP_2产生 2,但是当我按 Shift 或 Control 时,我希望同一个键产生一个Down事件,就像向下键一样。

所以我创建了一个新类型,其中包含以下添加的行:

    modifiers= Shift+Control+NumLock+LevelThree;
    map[Shift+NumLock]= Level1;
    preserve[Shift+NumLock]= None;
    ...
    map[Control+NumLock]= Level1;
    preserve[Control+NumLock]= None;

所以整个类型就变成了:

type "FOUR_LEVEL_MIXED_KEYPAD_CUST" {
    modifiers= Shift+Control+NumLock+LevelThree;
    map[Shift+NumLock]= Level1;
    preserve[Shift+NumLock]= None;
    map[NumLock]= Level2;
    map[Shift]= Level2;
    map[LevelThree]= Level3;
    map[NumLock+LevelThree]= Level3;
    map[Shift+LevelThree]= Level4;
    map[Shift+NumLock+LevelThree]= Level4;
    map[Control+NumLock]= Level1;
    preserve[Control+NumLock]= None;
    level_name[Level1]= "Base";
    level_name[Level2]= "Number";
    level_name[Level3]= "Alt Base";
    level_name[Level4]= "Shift Alt";
    };

我更改了该KP_2部分以这种方式考虑到这一点:

    key  <KP2> {
        type= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
        symbols[Group1]= [         Down,            KP_2,           U2193,           U21D3 ]
    };

(看到KP_Down变成了Down,我改了群名)

不幸的是,当我xkbcomp preserve_none.xkb $DISPLAY在 LibreOffice Calc 上运行 时,Shift + (NumLock) + KP2会产生类似 a 的内容Shift + Down(尽管有 ,它都会下降并选择preserve[...]=None),而当我按下 时Ctrl + KP2,基本上没有任何反应,我什至没有移动。

你看到我做错了什么了吗?谢谢!

注意:您可以在这里找到整个文件:http://paste.debian.net/1063341

答案1

嗯,我想我使用基于这个答案的东西找到了解决方案:https://superuser.com/questions/801611/how-to-make-all-applications-respect-my-modified-xkb-layout/1000320#1000320

所以首先,我不知道为什么,但似乎出于某种原因我需要使用type[Group1]=...而不是type=...即使有时它有效。

然后,关键是引入一些新的符号代码(不确定这个词好不好) osfDown/osfUp/.... 例如,这里我们说符号代码osfLeft应该被解释为按下按键<LEFT>,释放Shift按键后(至少我是这么理解的):

    interpret osfLeft {
        repeat= True;
        action = RedirectKey(keycode=<LEFT>, clearmodifiers=Shift);
    };

如果您想释放修饰符Control,则可以替换ShiftControl,或者即使Control+Shift您想清除两者。然后,您需要用KP_Left我们刚刚创建的符号代码替换旧的符号代码:

    key  <KP4> {
        type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD",
        symbols[Group1]= [ osfLeft,            KP_4,           U2190,           U21D0 ]
    };

这样,Shift/Control这将删除Shift/Control修饰符(同样,取决于您在 中配置的内容osfLeft),而不是生成 KP_Left (并最终生成关联的,具体取决于您按下的内容)。

因此,在这一步中,这是第一个解决方案:

# Load with xkbcomp shift_numpad.xkb $DISPLAY
# List modifiers: xmodmap -pm
xkb_keymap {
    xkb_keycodes { 
        include "evdev+aliases(azerty)"
    };
    xkb_types { 
        include "complete"  
    };
    xkb_compat { 
        include "complete"
        interpret osfLeft {
            repeat True;
            action = RedirectKey(keycode=<LEFT>, clearmodifiers=Shift);
        };
        interpret osfRight {
            repeat= True;
            action = RedirectKey(keycode=<RGHT>, clearmodifiers=Shift);
        };
        interpret osfUp {
            repeat= True;
            action = RedirectKey(keycode=<UP>, clearmodifiers=Shift);
        };
        interpret osfDown {
            repeat= True;
            action = RedirectKey(keycode=<DOWN>, clearmodifiers=Shift);
        };
    };
    xkb_symbols { 
        include "pc+fr(oss)+fr(bepo):2+inet(evdev)+ctrl(swapcaps)"
        key  <KP8> {
            type= "FOUR_LEVEL_MIXED_KEYPAD",
            symbols[Group1]= [ osfUp,            KP_8,           U2191,           U21D1 ]
        };
        key  <KP4> {
            type= "FOUR_LEVEL_MIXED_KEYPAD",
            symbols[Group1]= [ osfLeft,            KP_4,           U2190,           U21D0 ]
        };
        key  <KP5> {
            type= "FOUR_LEVEL_MIXED_KEYPAD",
            symbols[Group1]= [ osfDown,            KP_5,           U2194,           U21D4 ]
        };
        key  <KP6> {
            type= "FOUR_LEVEL_MIXED_KEYPAD",
            symbols[Group1]= [ osfRight,            KP_6,           U2192,           U21D2 ]
        };
        key  <KP2> {
            type= "FOUR_LEVEL_MIXED_KEYPAD",
            symbols[Group1]= [ osfDown,            KP_2,           U2193,           U21D3 ]
        };

    };
    xkb_geometry { 
        include "pc(pc105)" 
    };
};

但请注意,该类型"FOUR_LEVEL_MIXED_KEYPAD"没有为 定义任何内容Control,在我的例子中,我希望必须Shift+2等于Shift+Down(即 select),但也Control+2生成Down不带任何修饰符的 a 。因此,我需要更新 的定义osfLeft以删除修饰符Control,但保留修饰符(Shift如果它已经存在)。然后,我需要定义一个也映射Ctrl到级别 1 的自定义类型:

    type "FOUR_LEVEL_MIXED_KEYPAD_CUST" {
        modifiers= Shift+NumLock+LevelThree+Control;
        map[Shift+NumLock]= Level1;
        map[Control+NumLock]= Level1;
        map[NumLock]= Level2;
        map[Shift]= Level2;
        map[Control]= Level2;
        map[LevelThree]= Level3;
        map[NumLock+LevelThree]= Level3;
        map[Shift+LevelThree]= Level4;
        map[Shift+NumLock+LevelThree]= Level4;
        level_name[Level1]= "Base";
        level_name[Level2]= "Number";
        level_name[Level3]= "Alt Base";
        level_name[Level4]= "Shift Alt";
    };

如果我把它们放在一起,就会得到:

# Load with xkbcomp shift_numpad.xkb $DISPLAY
# List modifiers: xmodmap -pm
xkb_keymap {
    xkb_keycodes { 
        include "evdev+aliases(azerty)"
    };
    xkb_types { 
        include "complete"
        type "FOUR_LEVEL_MIXED_KEYPAD_CUST" {
            modifiers= Shift+NumLock+LevelThree+Control;
            map[Shift+NumLock]= Level1;
            map[Control+NumLock]= Level1;
            map[NumLock]= Level2;
            map[Shift]= Level2;
            map[Control]= Level2;
            map[LevelThree]= Level3;
            map[NumLock+LevelThree]= Level3;
            map[Shift+LevelThree]= Level4;
            map[Shift+NumLock+LevelThree]= Level4;
            level_name[Level1]= "Base";
            level_name[Level2]= "Number";
            level_name[Level3]= "Alt Base";
            level_name[Level4]= "Shift Alt";
        };
    };
    xkb_compat { 
        include "complete"
        interpret osfLeft {
            repeat= True;
            action = RedirectKey(keycode=<LEFT>, clearmodifiers=Control);
        };
        interpret osfRight {
            repeat= True;
            action = RedirectKey(keycode=<RGHT>, clearmodifiers=Control);
        };
        interpret osfUp {
            repeat= True;
            action = RedirectKey(keycode=<UP>, clearmodifiers=Control);
        };
        interpret osfDown {
            repeat= True;
            action = RedirectKey(keycode=<DOWN>, clearmodifiers=Control);
        };
    };
    xkb_symbols { 
        include "pc+fr(oss)+fr(bepo):2+inet(evdev)+ctrl(swapcaps)"
        key  <KP8> {
            type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
            symbols[Group1]= [ osfUp,            KP_8,           U2191,           U21D1 ]
        };
        key  <KP4> {
            type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
            symbols[Group1]= [ osfLeft,            KP_4,           U2190,           U21D0 ]
        };
        key  <KP5> {
            type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
            symbols[Group1]= [ osfDown,            KP_5,           U2194,           U21D4 ]
        };
        key  <KP6> {
            type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
            symbols[Group1]= [ osfRight,            KP_6,           U2192,           U21D2 ]
        };
        key  <KP2> {
            type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD_CUST",
            symbols[Group1]= [ osfDown,            KP_2,           U2193,           U21D3 ]
        };

    };
    xkb_geometry { 
        include "pc(pc105)" 
    };
};

注意:如果您想使用 Super/LWIN 键,则完全相同,但使用Mod4代替Shift,并确保您有

            modifier_map Mod4 { <LWIN> };

在符号部分!

相关内容