Kmonad,一个自由改变键盘布局的软件。

kmonad主要解决的是键盘的布局问题。

因为键盘的一般布局大量使用小拇指,来按esc等按键,kmonad可以缓解这个问题。

还有一些小键盘,缺少一些按键,或者你的键盘有一些按键坏了,都可以用kmonad。

kmonad也可以让那些不具备改键等功能的键盘实现复杂的功能。​

kmonad也可以在linux,mac运行,但是需要稍微调整配置文件。

kmonad主要难点是配置文件,这里简单介绍一下,并提供一个windows下可以快速使用的配置。

基础配置

我们主要关注deflayer default

(defcfg
  ;; For Linux
  ;; input  (device-file "/dev/input/by-id/usb-04d9_daskeyboard-event-kbd")
  ;; output (uinput-sink "My KMonad output"
    ;; To understand the importance of the following line, see the section on
    ;; Compose-key sequences at the near-bottom of this file.
    ;; "/run/current-system/sw/bin/sleep 1 && /run/current-system/sw/bin/setxkbmap -option compose:ralt")
  ;; cmp-seq ralt    ;; Set the compose key to `RightAlt'
  ;; cmp-seq-delay 5 ;; 5ms delay between each compose-key sequence press

  ;; For Windows
  input  (low-level-hook)
  output (send-event-sink)

  ;; For MacOS
  ;; input  (iokit-name "my-keyboard-product-string")
  ;; output (kext)

  ;; Comment this is you want unhandled events not to be emitted
  fallthrough true

  ;; Set this to false to disable any command-execution in KMonad
  allow-cmd true
)

(deflayer default
  _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _    _    _   
  _    _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _   
  _    _    _              _              _    _    _    _   
)

(defsrc
  esc  f1   f2   f3   f4   f5   f6   f7   f8   f9   f10  f11  f12
  grv  1    2    3    4    5    6    7    8    9    0    -    =    bspc  
  tab  q    w    e    r    t    y    u    i    o    p    [    ]    \   
  caps a    s    d    f    g    h    j    k    l    ;    '    ret
  lsft z    x    c    v    b    n    m    ,    .    /    rsft  
  lctl lmet lalt           spc            ralt rmet cmp  rctl  
)

注意,如果你的键盘没有f功能键,需要在deflayer和defsrc删除对应的按键。如果你的键盘没有数字键也要删除对应的按键。你可以去仓库找一些现成的键位。kmonad/keymap at master · kmonad/kmonad (github.com)

调换caps和lctl

(deflayer default
  _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _    _    _   
  _    _    _    _    _    _    _    _    _    _    _    _    _    _
  lctl _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _   
  caps _    _              _              _    _    _    _   
)

很简单,调换两个键的位置,非常直观。

单击lctl输出esc

esc太远了,还有按错的问题,kmonad区分按下弹起和按住两个行为,这样一个键就实现了两个功能。

(defalias
  ce (tap-next-release esc lctl)
)
(deflayer default
  _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _    _    _   
  _    _    _    _    _    _    _    _    _    _    _    _    _    _
  @ce  _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _   
  caps _    _              _              _    _    _    _   
)

顺便一说,这个配置文件是lisp语言,主要语法是(func arg1 arg2)。

加层

但是这样键位还是不够,特别是对于60键位之类的键盘,这个就需要加一层键位,通过一个按键启动这个层,不当的层设置可能会导致你回不到原来的层,这里只介绍按下时触发的层。

(deflayer default
  _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _    _    _   
  _    _    _    _    _    _    _    _    _    _    _    _    _    _
  @ce  _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    _    _    _    _    _    _   
  caps _    _              @spc           _    _    _    _   
)

...

;; ---- Space ----- {{{
(defalias spc (tap-hold 200 spc (layer-toggle space)))
(deflayer space 
  _    _    _    _    _    _    _    _    _    _    _    _    _  
  _    _    _    _    _    _    _    _    _    _    _    _    _    _  
  _    _    _    _    _    _    _    _    _    _    _    _    _    _
  _    _    _    _    _    _    left down up   rght _    _    _  
  _    _    _    _    _    _    _    _    _    _    _    _  
  _    _    _              _              _    _    _    _  
)
;; ---------------- }}}

我们先定义了一个别名,spc,它在200毫秒完成单击空格的时候会发送空格,按住的时候跳转到space

再定义了一个space的层,在上面将hjkl变成上下左右。

最后我们用@spc替换原来的空格。

之后可以参考仓库中其它的布局,比如下面这个mac的布局。

因为winodws的空格比较长,把右alt改成退格并不是很方便,这也是传统键盘的通病,就是太不能利用大拇指。

但是把数字键和标点集中在主键盘区可以参考。

最后,配置文件就为这样。

	(defcfg
	  ;; For Linux
	  ;; input  (device-file "/dev/input/by-id/usb-04d9_daskeyboard-event-kbd")
	  ;; output (uinput-sink "My KMonad output"
		;; To understand the importance of the following line, see the section on
		;; Compose-key sequences at the near-bottom of this file.
		;; "/run/current-system/sw/bin/sleep 1 && /run/current-system/sw/bin/setxkbmap -option compose:ralt")
	  ;; cmp-seq ralt    ;; Set the compose key to `RightAlt'
	  ;; cmp-seq-delay 5 ;; 5ms delay between each compose-key sequence press

	  ;; For Windows
	  input  (low-level-hook)
	  output (send-event-sink)

	  ;; For MacOS
	  ;; input  (iokit-name "my-keyboard-product-string")
	  ;; output (kext)

	  ;; Comment this is you want unhandled events not to be emitted
	  fallthrough true

	  ;; Set this to false to disable any command-execution in KMonad
	  allow-cmd true
	)

	(defalias
	  ce (tap-next-release esc lctl)
	)

	(deflayer default
	  _    _    _    _    _    _    _    _    _    _    _    _    _
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _   
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _
	  @ce  _    _    _    _    _    _    _    _    _    _    _    _
	  _    _    _    @lw  _    _    _    @rs  _    _    _    _       
	  caps _    _              @spc           _    _    _    _       
	)

	(defsrc
	  esc  f1   f2   f3   f4   f5   f6   f7   f8   f9   f10  f11  f12
	  grv  1    2    3    4    5    6    7    8    9    0    -    =    bspc  
	  tab  q    w    e    r    t    y    u    i    o    p    [    ]    \   
	  caps a    s    d    f    g    h    j    k    l    ;    '    ret
	  lsft z    x    c    v    b    n    m    ,    .    /    rsft    
	  lctl lmet lalt           spc            ralt rmet cmp  rctl    
	)

	;; ---- Space ----- {{{
	(defalias spc (tap-hold 200 spc (layer-toggle space)))
	(deflayer space 
	  _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _
	  _    _    _    _    _    _    left down up   rght _    _    _  
	  _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _              _              _    _    _    _  
	)
	;; ---------------- }}}


	;; ---- Raise ----- {{{
	(defalias rs (tap-hold 150 m (layer-toggle raise)))
	(deflayer raise
	  _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    &    _    _    _    ^    \_   +    _    _    _
	  _    !    @    #    $    %    ^    &    *    \(   \)   |    _  
	  _    _    `    _    _    _    _    _    _    {    }    _  
	  _    _    _              _         _    _    _    _  
	)

	;; ---- Lower ----- {{{
	(defalias lw (tap-hold 150 c (layer-toggle lower)))
	(deflayer lower
	  _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    _    _    _    _    _    _    _    _    _    _  
	  _    _    _    _    _    _    1    2    3    -    =    _    _    _
	  _    _    _    _    _    _    4    5    6    _    _    \\   _  
	  _    _    ~    _    _    _    7    8    9    [    ]    _  
	  _    _    _              _         _    _    _    _  
	  
	)
	;; ---------------- }}}

你也可以尝试去运行命令,类似dat (cmd-button "date >> test.txt"),但是不太推荐滥用就是了。

你可以参考仓库中其他键位,甚至是其他软件的改键方式。如果这些不能满足你的需求,可以看看仓库的配置文件说明

也欢迎分享你的配置文件和思路。

对了,kmonad也是类似AHK通过发送消息来实现按键的,这和原来单击按键不同,有些软件可能不能响应按键。至少我发现listary不能响应ctrl触发。​

2 个赞

很直观,改得键多了的话比起AHK应该优势明显,mark一下以后好推荐给别人。祝大家都能找到适合自己的键盘,我是再也不会回来了 :rofl:

论按键映射,功能最完备的应该是rewasd,可惜是收费软件

手柄玩家可以考虑,可惜主机禁了太久了,几乎没什么人用手柄。
我想起来了,现在一些好的手柄应该也可以做到,我买了几乎没用。

这种软件玩到最后就是:

软件改键是有局限性的……jojo!我玩客制化啦!

2 个赞

请问一下这个软件能不能把Linux/Windows系统的快捷键改成macOS的?

我没有mac,自己去试试或者等一个有缘人吧

对于键盘带fn键的,这个软件的改键可以对fn生效吗,之前看市面上大部分的按键映射软件都无法对fn进行重映射
不过好像很多带fn的键盘是把逻辑直接写到芯片里的,单独按并不输出信号,遇到这种情况似乎是没辙

是的,除非键盘能改变FN的键值,不然FN不能改。

我启动这个东西之后,vscode 的 vim 插件就不响应长按了。。。

不是vscode的按住自动重复不行,是所有由Kmonad修改过的都不行。kmonad里面没有实现自动重复,好像在PR里。

开debug log里面看,按住之后没有release就是重复press了,不知道是不是这个导致的

不知道,反正说明里提到没有提供自动重复,Issue也有提到类似的问题。我不太在乎,一般退格才会用长按,现在我把ctrl退格方向全部移过来了,没有就没有吧。

请问,统信UOS怎么安装这个软件?arm64的处理器。

顺便说一句,对于windows用户可以尝试基本与这个相同的 kanata,kmonad社群对于windows的支持其实并不是那么好

1 个赞