From ffa579d3be13614692b13820f1b8f6b39ab0a222 Mon Sep 17 00:00:00 2001 From: Csaba Marosi <4bea6c869366227b879ffe4abad50c@gmail.com> Date: Sun, 3 Jan 2016 08:20:30 +0000 Subject: [PATCH] Using 'xinput test' instead of showkey This change removes the sudo dependency. Note: inside a Docker container showkey does not work. --- README.md | 4 ++-- keyfreq.sh | 22 ++++++++++++++-------- ulogme.sh | 3 +-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 08e6d44..4131f63 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ See a blog post (along with multiple screenshots) describing the project [here.] **To start recording** 1. Clone the repository to some folder: `$ git clone https://github.com/karpathy/ulogme.git` -2. If you're on Ubuntu, make sure you have the dependencies: `$ sudo apt-get install xdotool`. On Fedora, you may also need `sudo yum install gnome-screensaver`. -3. `cd` inside and run `$ ./ulogme.sh` (note: this will ask you for sudo authentication which is required for `showkey` command). This will launch two scripts. One records the frequency of keystrokes and the other records active window titles. Both write their logs into log files in the `logs/` directory. Every log file is very simply just the unix time stamp followed by data, one per line. +2. If you're on Ubuntu, make sure you have the dependencies: `$ sudo apt-get install xinput xdotool`. On Fedora, you may also need `sudo yum install gnome-screensaver`. +3. `cd` inside and run `$ ./ulogme.sh`. This will launch two scripts. One records the frequency of keystrokes and the other records active window titles. Both write their logs into log files in the `logs/` directory. Every log file is very simply just the unix time stamp followed by data, one per line. 4. For **OSX** only: there might be an additional step where you have to go to System Preferences > Security & Privacy > Accessibility, and make sure that Terminal (or iTerm2, or whatever you use to launch ulogme) is checked. If it wasn't checked previously and you just checked it, you may need to restart ulogme. If you don't do this step, you might find that window logging works but keypress logging doesn't. **The user interface** diff --git a/keyfreq.sh b/keyfreq.sh index c4a553f..e364d12 100755 --- a/keyfreq.sh +++ b/keyfreq.sh @@ -7,21 +7,27 @@ LANG=en_US.utf8 -helperfile="logs/keyfreqraw.txt" # temporary helper file +helperfile="logs/keyfreqraw" # temporary helper file mkdir -p logs while true do - showkey > $helperfile & - PID=$! - - # work in windows of 9 seconds - sleep 9 - kill $PID + windowLength=9 #seconds + # check each possible keyboard + keyboardIds=$(xinput | grep 'slave keyboard' | grep -o 'id=[0-9]*' | cut -d= -f2) + # and grep only the updated ones + filesToGrep='' + for id in $keyboardIds; do + fileName="$helperfile.$id" + timeout $windowLength xinput test $id > $fileName & + filesToGrep+="$fileName " + done + sleep $windowLength + sleep .5 #make sure that all `xinput test` finished # count number of key release events - num=$(cat $helperfile | grep release | wc -l) + num=$(grep release $filesToGrep | wc -l) # append unix time stamp and the number into file logfile="logs/keyfreq_$(python rewind7am.py).txt" diff --git a/ulogme.sh b/ulogme.sh index b09e5ba..31bd004 100755 --- a/ulogme.sh +++ b/ulogme.sh @@ -5,7 +5,6 @@ if [ "$(uname)" == "Darwin" ]; then ./osx/run_ulogme_osx.sh else # Assume Linux - sudo echo -n "" - sudo ./keyfreq.sh & + ./keyfreq.sh & ./logactivewin.sh fi