在 EmacsW32 中向操作系统发送击键
如果您用多种语言编写文本并使用 Emacs,您可能知道,Emacs 有自己独立于 Windows(或其他操作系统)的输入法系统。 可以使用 toggle-input-method
命令切换输入法。 当 Windows 语言更改时,Emacs 会收到
按键。 然后我想将
绑定到 toggle-input-method
。 不幸的是,如果我这样做,
(global-set-key (kbd "<language-change>") 'toggle-input-method)
Windows 语言和输入法都会被切换。 所以我需要类似
(defvar safe-language-change-flag nil)
(defun safe-language-change ()
(interactive)
(setq safe-language-change-flag (not safe-language-change-flag))
(when safe-language-change-flag
(toggle-input-method)
(send-key (kbd "<language-change>"))))
(global-set-key (kbd "<language-change>") 'safe-language-change)
我似乎找不到的是一个函数调用,它将向操作系统发送密钥(或以另一种方式更改系统语言)。
As you probably know if you write text in multiple languages and use Emacs, Emacs has its own input method system independent of Windows (or other operating systems). Input methods can be toggled with toggle-input-method
command. When Windows language changes, Emacs receives a <language-change>
keypress. I would like then to bind <language-change>
to toggle-input-method
. Unfortunately, if I do just
(global-set-key (kbd "<language-change>") 'toggle-input-method)
both Windows language and input method will be toggled. So I need something like
(defvar safe-language-change-flag nil)
(defun safe-language-change ()
(interactive)
(setq safe-language-change-flag (not safe-language-change-flag))
(when safe-language-change-flag
(toggle-input-method)
(send-key (kbd "<language-change>"))))
(global-set-key (kbd "<language-change>") 'safe-language-change)
What I can't seem to find is a function call which would send a key to the operating system (or change the system language in another way).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了确保您希望这种情况发生:您更改操作系统中的语言。 Emacs 获取此事件,将按键发送回操作系统,然后取消更改语言。
您可以调用外部实用程序来执行此操作。
不过,我不确定你为什么要这样做。
如果您更改了操作系统的语言,则让操作系统处理输入法。 如果您不想使用操作系统的输入法,请在 emacs 内执行切换输入法,而不必担心操作系统的状态。
我错过了什么吗?
Just to make sure, you want this to happen: You change the language in the OS. Emacs gets this event, sends a keypress back to the OS, and then un-changes the language.
You may be able to call an external utility to do this.
I'm not sure why you want to do this, though.
If you've changed the OS's language, then let the OS handle the input method. If you don't want to use your OS's input method, then do toggle-input-method inside emacs, and don't bother worrying about the OS's state.
Am I missing something?
这正是我想要得到的结果。 困难在于我发现自己一直在切换操作系统输入法,因为“按 Shift 切换语言”现在已经成为我手指记忆的一部分。
This is precisely the result I want to get. The difficulty is that I find myself switching the OS input method instead all the time because "press Shift to switch language" is a part of my finger memory by now.