【问题标题】:Remap Win, Ctrl and Alt keys on Linux在 Linux 上重新映射 Win、Ctrl 和 Alt 键
【发布时间】:2015-11-15 21:45:36
【问题描述】:

问题:

如何在 Linux 系统范围内重新映射(交换)修饰键?

解释:

我想在我的 PC 上安装 Debian Jessie 以将其与 Emacs 一起使用。我有一台带有 Emacs 的 MacBook,主要使用它。以下是笔记本电脑上按键的排列方式:

fn ctrl alt cmd 空格键 cmd alt

fn 在我的 Emacs 工作流程中未使用,其他键配置如下:

  • ctrl 充当Hyper
  • alt 充当Meta
  • cmd 充当Control

这些配置简化了我的 Emacs 体验(大拇指点击 Control cmd 键)并且我习惯了这种键绑定。

默认情况下,alt 被用作Meta,而ctrl 被用作Control,键被交换并且大拇指放在@987654328 @

我想以同样的方式在 Linux 上配置我的按键,这是我 PC 键盘上的内容:

ctrl win alt 空格键 alt win 菜单 ctrl

所以,为了对应我的笔记本电脑键,我希望 win 键映射到 Alt 修饰符,而 alt 键映射到 Control 修饰符.在这种情况下,ctrl 可以用作Super 修饰符,而 menu 可以保持不变。

是否可以在 Linux (Debian) 上进行系统范围的此类配置?


最后,我通过以下配置实现了我的目标:

!file ~/.Xmodmap

clear control
clear mod1
clear mod4


keycode 37  = Super_L     
! left  Ctrl becomes Super
keycode 64  = Control_L
! left  Alt  becomes Control 
keycode 133 = Alt_L Meta_L
! left  Win  becomes Alt
keycode 108 = Control_R
! right Alt  becomes Control 
keycode 134 = Alt_R Meta_R
! right Win  becomes Alt
keycode 105 = Super_R
! right Ctrl becomes Super


add control = Control_L Control_R
add mod1 = Alt_L Meta_L
add mod4 = Super_L Super_R

另外,这里是similar question,提供非常有用且简单的指南。

【问题讨论】:

    标签: linux emacs configuration keyboard


    【解决方案1】:

    全面披露

    我是 Kinto 的作者。

    您可能会发现 Kinto 很有用。这是我最近创建的一个项目,经过几年以几种不同的方式解决这个问题后,我现在觉得它足够可靠,可以分享。

    Kinto 安装程序仅使用 python 进行初始安装,之后它只是一个 systemd 服务、bash、xprop、setxkbmap 和 xkbcomp。就我而言,这是您将要找到的最快、最原生的解决方案。

    Xmodmap 也已失效,它将无法与 Wayland 一起使用。

    https://github.com/rbreaves/kinto

    https://medium.com/@benreaves/kinto-a-mac-inspired-keyboard-mapping-for-linux-58f731817c0

    这里还有一个要点,如果您只是想了解这一切的核心,它不会在需要时更改您的键盘映射。 Gist 也不包括自定义 xkb 键盘映射文件,这些文件设置 macOS 样式光标/使用 Cmd 和箭头键的逐字操作。

    https://gist.github.com/rbreaves/f4cf8a991eaeea893999964f5e83eebb

    要点内容

    # permanent apple keyboard keyswap
    echo "options hid_apple swap_opt_cmd=1" | sudo tee -a /etc/modprobe.d/hid_apple.conf
    update-initramfs -u -k all
    
    # Temporary & instant apple keyboard keyswap
    echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd
    
    # Windows and Mac keyboards - GUI (Physical Alt is Ctrl, Physical Super is Alt, Physical Ctrl is Super)
    setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win
    
    # Windows and Mac keyboards - Terminal Apps (Physical Alt is Super, Physical Super is Alt, Physical Ctrl is Ctrl)
    setxkbmap -option;setxkbmap -option altwin:swap_alt_win
    
    #
    # If you want a systemd service and bash script to help toggle between
    # GUI and Terminal applications then look at project Kinto.
    # https://github.com/rbreaves/kinto
    #
    # Note: The above may not work for Chromebooks running Linux, please look
    # at project Kinto for that.
    #
    # If anyone would like to contribute to the project then please do!
    #
    

    【讨论】:

    • 通知@Makyen披露。
    【解决方案2】:

    可能比使用xmodmap 更容易检查setxkbmap 给出的键盘布局选项。这些选项实现了常见的xmodmap 更改,因此它们很可能包含您想要的内容。

    例如,我喜欢-option ctrl:nocaps,它在caps lock 所在的位置添加了另一个control。考虑文件/usr/share/X11/xkb/rules/base.lst 以获得标准选项列表。

    但是,xmodmapsetxkbmap 都不包括纯文本 tty 终端(非 X)的键盘设置。

    【讨论】:

      【解决方案3】:

      xmodmap 是开始的地方,请记住 X 对 HyperMeta 一无所知,因此您必须调查以查看 emacs 用于这些编号的修饰符(mod4、mod5 等)修饰符。

      这里有一些有用的链接:

      【讨论】:

      • 我仍然不知道如何在系统范围内交换密钥,甚至可以在启动时进行这种配置吗?
      • 在启动时,没有 X 运行,正如@Hannes 指出的那样,没有任何 X 设置适用。但是,大多数 emacs 用户依赖于 GUI,并且(与 setxkbmap 不同)可以从 xmodmap 的手册页中获得有用的信息——这就是我提供的答案。
      • 我想要的不是配置 Emacs 密钥,而是将所有系统应用等的 win 密钥重新映射到 altctrl 等。
      • ...xmodmap 是为实现该目标而开始的地方,因为它正是这样做的。
      猜你喜欢
      • 2018-12-15
      • 2014-03-17
      • 1970-01-01
      • 2019-09-16
      • 2020-04-02
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多