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).