1

In Elisp, I need to use (event-modifiers EVENT) to determine if last event involves any modifier keys pressed. I'm using read-key-sequence/read-key-sequence-vector to capture the event. The prior returns a string while the later returns a vector. Neither seems to qualify as a valid EVENT type argument. How can I convert a key sequence string or a vector to such EVENT object? Thanks.

4

2 回答 2

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))
于 2013-10-02T02:05:19.783 回答
2

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

于 2013-10-02T02:07:44.940 回答