gpt4 book ai didi

Emacs:如何绑定(bind)两次点击的键?

转载 作者:行者123 更新时间:2023-12-01 10:11:05 25 4
gpt4 key购买 nike

我正在使用 Emacs (23) 并且我正在将 C-. 组合键绑定(bind)到一个函数:

(global-set-key (kbd "C-.") 'myfunction)

是否可以绑定(bind)一个快速的“双击”键?例如,我想在快速键入 . 两次时调用函数 myfunction

最佳答案

没有内置任何内容,但您可以使用此代码。将变量 dc-single-click-cmddc-double-click-cmd 自定义为您想要的命令。

注意:这会带来轻微的延迟,b/c 代码需要等待一点时间来确定事件是单击还是双击。

(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:如何绑定(bind)两次点击的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4923723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com