重新映射电源键以删除

nat*_*han 15 x11 xmodmap xkb keyboard-layout

我有一台运行 Ubuntu 13.10 和 FluxBox 的 macbook pro。不幸的是,电源按钮实际上位于我希望删除键所在的退格键上方。在 OS X 中,PowerKey 程序可用于重新映射电源键以进行删除。我如何在 X Windows 中做类似的事情?

我通过编辑/etc/systemd/logind.conf和设置禁用了电源键HandlePowerKey = ignore 之后,我可以在不关闭笔记本电脑的情况下按下电源按钮。

运行xev -event keyboard显示电源键的 KeyPress 通常被另一个进程吃掉:

MappingNotify event, serial 36, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeymapNotify event, serial 36, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeymapNotify event, serial 37, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
Run Code Online (Sandbox Code Playgroud)

但是,通过直接从控制台仅运行 xterm,我能够成功获取密钥代码并重新映射密钥。

xinit /usr/bin/xterm -- :1
xev -event keyboard | tee /tmp/junk.txt
tail -n ???? /tmp/junk.txt
MappingNotify event, serial 28, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 28, synthetic NO, window 0x600001,
    root 0xa1, subw 0x0, time 720369, (146,89), root:(148,91),
    state 0x0, keycode 124 (keysym 0x1008ff2a, XF86PowerOff), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x600001,
    root 0xa1, subw 0x0, time 720369, (146,89), root:(148,91),
    state 0x0, keycode 124 (keysym 0x1008ff2a, XF86PowerOff), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

MappingNotify event, serial 29, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248
Run Code Online (Sandbox Code Playgroud)

此时,也可以使用 xmodmap 映射密钥。我将它映射到反斜杠,这比删除更容易看到:

 xmodmap -e "keycode 124 = backslash bar"
Run Code Online (Sandbox Code Playgroud)

我可以通过将它添加到运行来获得几乎没有功能的等效项,~/.fluxbox/keys但这既丑陋又慢到无法使用。

  # Remap the power off to a delete key...
  XF86PowerOff :Exec xdotool key Delete
Run Code Online (Sandbox Code Playgroud)

如何使用 xmodmap 或 setxkbmap 与普通窗口管理器同时使用电源按钮?

Mik*_*rst 0

很难确定。这些可能是您已经尝试过的事情,但它们可能会带来一个简单的解决方案。

xmodmap 是否适用于其他键,或者 Fluxbox 正在做的事情是否完全破坏了 xmodmap?

如果启动 x,modmap 电源键,然后启动 Fluxbox,会发生什么?映射是否粘住?

如果在fluxbox工作之前运行xmodmap并保留您的设置,您可以编写一个shell脚本以正确的顺序调用两者,或者如果您使用gdm,它应该在fluxbox进入图片之前自动为您读取~/.xmodmap或读取。~/.xmodmaprc