I'm trying to implement a keylogger in Emacs (for my own, non-nefarious purposes).
It seems that I can reliably capture the last command through real-last-command
in the pre-command-hook
So, I can do something like:
(setq keylog-list nil)
(defun my-keylogger-function ()
(setq keylog-list (cons real-last-command keylog-list)))
(add-hook 'pre-command-hook 'my-keylogger-function)
After a few movement commands, we get
keylog-list's value is
(describe-variable left-char left-char previous-line previous-line left-char eval-last-sexp)
However, I'm interested in capturing the arguments to these commands as well (e.g. the arguments to left-char
, which will by default be 1
but may be different if prefix arguments are used.
Is there a way to access the args as well? Something like real-last-command-arglist
?
A keylogger is also built into emacs: (open-dribble-file).
Why do you log the last (i.e. previous) command? If you log this-command
instead, you can log current-prefix-arg
, which corresponds to the prefix argument used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With