I'm writing some code where I have to identify the command for the last key pressed. Sometimes I need to look up a combination of this key with another one. I use the key-binding
function for that. It works most of the time but not for all keys. For example it does not work for the backspace key:
(progn
(read-key)
(key-binding (vector last-input-event))) ;; > nil for backspace
I can work around this by checking for backspace manually but I wonder if there is a more reliable way that works for all/most situations?
I use last-input-event
because it is after exiting a keymap through the default binding [t]
.
Edit:
Based on the accepted answer I'm using something like the following which seems to work very well:
(progn
(read-key)
(key-binding (kbd (edmacro-format-keys (vector last-input-event)))))
last-command
variable: gnu.org/software/emacs/manual/html_node/eintr/…(key-binding (vector (read-char)))
? It looks like(vector last-input-event)
doesn't always hold a valid key representation, at least for some function keys such as backspace, tab and return(recent-keys t)
and the definition ofview-lossage
.