I need to record every keystroke and store in a file in the user directory ~, when using my account, I am not sudoer and I cannot install programs (like logKeys) in any way. How could I do so using terminal?
NOTE: This question it's not a duplicate of the other mention question; in this question I'm asking about every keystroke, while in the other the asker asked about keystroke in terminal session.
Best Answer
xinput test
can report all keyboard events to the X server. On a GNU system:If you want to get key names from the key codes, you could post-process that output with:
Add
> file.log
to store in a log file. Or| tee file.log
to both log and see it.xinput
queries the XinputExtension of the X server. That's as close as you're going to get as a standard (I am not aware of any standard that covers X utilities) or common command to do that. That also does not require root privileges.If the X server and xinput support version 2 of the XinputExtension, you can use
test-xi2
instead oftest
which gives more information, in particular the state of the modifiers (shift, ctrl, alt...). Example:You can translate the keycode (in
detail
) to a keysym with the help ofxmodmap -pke
again, and theeffective
modifier bitmask to something more helpful with the help ofxmodmap -pm
. For instance:would output:
when I press Shift+Alt+q when num-lock is on.
Note that you don't need to have super-user privileges to install a program. If you have write access to somewhere on the file system where execute permission is granted (your home directory,
/tmp
,/var/tmp
...) then you can copy anxinput
command from a compatible system there and execute it.