neomacs icon indicating copy to clipboard operation
neomacs copied to clipboard

[Bug][Windows] Ctrl+Alt+字母 被解析为 C-M-<win-VK>,C-M- 绑定无法触发

Open iysun opened this issue 2 weeks ago • 0 comments

环境

  • NEO Emacs 0.0.20(Windows x86_64,安装包版)
  • GNU Emacs 31.1(同一台机器,作对照)
  • 两边都用 -Q 加载同一份演示脚本

复现

(global-set-key (kbd "C-M-n") (lambda () (interactive) (message "C-M-n fired")))

按 Ctrl+Alt+n。

实际

NEO Emacs 收到的事件是 C-M-<win-78>,绑定不触发;同一配置在 GNU Emacs 下收到 C-M-n,正常触发。

其它组合:Ctrl+Alt+p → C-M-<win-80>,Ctrl+Alt+a → C-M-<win-65>,Ctrl+Alt+# → C-M-S-<win-51>。C-n、M-j 在 NEO Emacs 下正常。

GNU Emacs 31.1 vs NEO Emacs 0.0.20(同一个脚本、同一个按键)

期望

Ctrl+Alt+<letter> 与 GNU Emacs 一致,产生 C-M-<letter>。

初步定位

Windows 把 Ctrl+Alt 当 AltGr,ToUnicode 不产出字符,winit 返回 Key::Unidentified(NativeKey::Windows(VK));translate_key_input 走 keysym::native_key_windows() 的保留区并命名成 win-<VK 十进制>(crates/neovm-eval/src/emacs_core/runtime/eval/keyboard/keysym.rs),事件于是变成 C-M-win-78。GNU 的 w32 后端直接用 VK + 修饰键状态构造字符,所以没这个问题。当前 main 分支的逻辑相同。

临时 workaround

(when (eq system-type 'windows-nt)
  (dolist (c (number-sequence ?a ?z))
    (define-key key-translation-map
      (kbd (format "C-M-<win-%d>" (- c 32)))
      (kbd (format "C-M-%c" c)))))

iysun avatar Nov 13 '26 06:11 iysun