Skip to content

Commit

Permalink
Using 'xinput test' instead of showkey
Browse files Browse the repository at this point in the history
This change removes the sudo dependency.
Note: inside a Docker container showkey does not work.
  • Loading branch information
csmarosi committed Jan 3, 2016
1 parent 1598f97 commit ffa579d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
22 changes: 14 additions & 8 deletions keyfreq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions ulogme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ffa579d

Please sign in to comment.