emacselisp

Emacs attach an action to any key pressed


Suppose, I have the code:

(defun dummy ()
      (interactive)
      (message "aaa"))

(local-set-key (kbd "<left>") 'dummy)

When you click <left> key in the current buffer, it will print "aaa".

Is it possible to attach this action to any key pressed?


Solution

  • Here is the solution:

    (defun dummy ()
          (interactive)
          (message "aaa"))
    
    (local-set-key [t] 'dummy)