将elisp事件字符串/向量转换为EVENT对象

时间:2013-10-02 01:39:41

标签: emacs elisp

在Elisp中,我需要使用(事件修饰符EVENT)来确定最后一个事件是否涉及按下任何修改键。我正在使用read-key-sequence / read-key-sequence-vector来捕获事件。先前返回一个字符串,而后一个返回一个向量。似乎都没有资格作为有效的EVENT类型参数。如何将键序列字符串或向量转换为此类EVENT对象?感谢。

2 个答案:

答案 0 :(得分:3)

函数event-modifiers需要单个事件。键序列通常不是单个事件。有关分析键序列中事件的示例,请参阅describe-key中定义help.el的代码。例如,这一点:

    ;; If KEY is a down-event, read and include the
    ;; corresponding up-event.  Note that there are also
    ;; down-events on scroll bars and mode lines: the actual
    ;; event then is in the second element of the vector.
    (and (vectorp key)
     (let ((last-idx (1- (length key))))
       (and (eventp (aref key last-idx))
        (memq 'down (event-modifiers (aref key last-idx)))))
     (or (and (eventp (aref key 0))
          (memq 'down (event-modifiers (aref key 0)))
          ;; However, for the C-down-mouse-2 popup
          ;; menu, there is no subsequent up-event.  In
          ;; this case, the up-event is the next
          ;; element in the supplied vector.
          (= (length key) 1))
         (and (> (length key) 1)
          (eventp (aref key 1))
          (memq 'down (event-modifiers (aref key 1)))))
     (read-event))

答案 1 :(得分:2)

您在问题中给出了答案:/...如果是最后一个事件... /,那么您想要使用read-key-sequence-vector返回的事件序列的最后一个元素。例如。 (aref keys (1- (length keys))