Emacs:如何绑定两次敲击的密钥? [英] Emacs: how to bind a key tapped twice?
问题描述
我正在使用Emacs(23),并且将 C-绑定到
组合键上。
I am using Emacs (23) and I am binding the C-.
key combination to a function:
(global-set-key (kbd "C-.") 'myfunction)
是否可以绑定快捷键双击?例如,我想在键入时调用函数
快速两次。 myfunction
。
Is it possible to bind a quick "double tap" of a key? For example, I would like to call a function myfunction
when typing .
quickly two times.
推荐答案
没有内置任何内容,但是您可以使用此代码。将变量 dc-single-click-cmd
和 dc-double-click-cmd
自定义为您想要的命令
There isn't anything built in, but you can use this code. Customize the variables dc-single-click-cmd
and dc-double-click-cmd
to be the commands you want.
注意:这会带来一些延迟,因为代码需要等待一点时间才能确定事件是单击还是双击。
Note: this introduces a slight delay, b/c the code needs to wait for a little bit of time to determine whether the event was a single or double click.
(defvar dc-single-click-cmd 'dc-example-single-click)
(defvar dc-double-click-cmd 'dc-example-double-click)
(defvar dc-click-timer nil
"Pending single-click event.")
(defun dc-example-single-click ()
(interactive)
(message "A single click just happened."))
(defun dc-example-double-click ()
(interactive)
(message "Wait! I meant double click."))
(defun dc-click-cmd ()
"Either kick off a single click, or a double click."
(interactive)
(if dc-click-timer
(progn
(cancel-timer dc-click-timer)
(setq dc-click-timer nil)
(call-interactively dc-double-click-cmd))
(setq dc-click-timer (run-at-time (when double-click-time
(/ 1000.0 double-click-time))
nil
'dc-call-single-click))))
(defun dc-call-single-click ()
"spawn the single click"
(setq dc-click-timer nil)
(call-interactively dc-single-click-cmd))
这篇关于Emacs:如何绑定两次敲击的密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!