You are not logged in.
I want to record all my keystrokes, just to see the frequency of some keys. There is a bunch of keyloggers on google that captures keystrokes, but none that is good and is in the AUR. Isn't it possible to do just with a little shell script? I don't mind if i have to keep the terminal open, and there is no need for any daemon/advanced stuff. Could you record a /dev/something or similar?
Offline
so you tried lkl and pykeylogger? maybe a better solution would be to fix the problems that are in those packages rather from starting anew.
Offline
vim/nano ? (kidding)
Offline
I read reviews of them, and they didn't seem overly good, and in one post it said something like "advanced users can do a simple script while newbies have to rely on programs like this" But I haven't found any simple scripts.
Maybe you could run
$ showkey
pipe the result to a file and then convert the keycodes to letters. Too bad that doesn't work in X.
Offline
You run into buffering problems, try this out:
sudo hexdump -e '48/1 "%x " "\n"' /dev/input/event1 | awk '( $29 == 1) { print "PRESS: " $13 } ( $29 == 0 ) { print "RELEASE: " $13 }'
It will collect a lot of events and print them all at once and it won't even redirect to a file.
So you want an all-in-one program like the ones in AUR. It should be pretty simple to write your own:
#! /usr/bin/python
file=open("/dev/input/event1")
keymap={
'\x2c': 'z',
'\x2d': 'x',
'\x2e': 'c',
'\xc8': 'UP',
'\xd0': 'DOWN',
'\xcb': 'LEFT',
'\xcd': 'RIGHT',
'\x10': 'q',
'\x11': 'w',
'\x12': 'e',
'\x01': 'ESC',
'\x2a': 'LSHIFT',
'\x1c': 'ENTER',
}
while True:
event=file.read(48)
if event[28] == '\x01':
state="pressed:"
elif event[28] == '\x00':
state="released:"
else:
continue
if event[12] in keymap:
print state, keymap[event[12]]
file.close()
You could write an action game in curses like that!
Offline
Thanks a lot, that's exactly what I were looking for. I'm sitting right now and tracking my number usage
Offline
Haha, check this out: (cursor=move, z=fire, q=quit)
#! /usr/bin/python
from curses import *
import threading
class ckeylog( threading.Thread ):
def run(self):
file=open("/dev/input/event1","rb")
keymap={
'\x2c': 'z',
'\x2d': 'x',
'\x2e': 'c',
'\xc8': 'UP',
'\xd0': 'DOWN',
'\xcb': 'LEFT',
'\xcd': 'RIGHT',
'\x10': 'q',
'\x11': 'w',
'\x12': 'e',
'\x01': 'ESC',
'\x2a': 'LSHIFT',
'\x1c': 'ENTER',
}
self.loop=True
while self.loop:
event=file.read(48)
if event[28] == '\x01':
state=True
elif event[28] == '\x00':
state=False
else:
continue
if event[12] in keymap:
self.map[keymap[event[12]]]=state
file.close()
def quit(self):
self.loop=False
keylog=ckeylog()
keylog.map={}
keylog.start()
def main(s):
curs_set(0)
ship=[
"| /\ |",
"+/!!\+",
"[]--[]",
]
shipx=0
shipy=0
bullet="* *"
bulletx=0
bullety=0
fire=False
while True:
(my,mx)=s.getmaxyx()
if 'q' in keylog.map:
if keylog.map['q']: keylog.quit(); return
if 'UP' in keylog.map:
if keylog.map['UP']: shipy=shipy-1
if 'DOWN' in keylog.map:
if keylog.map['DOWN']: shipy=shipy+1
if 'RIGHT' in keylog.map:
if keylog.map['RIGHT']: shipx=shipx+1
if 'LEFT' in keylog.map:
if keylog.map['LEFT']: shipx=shipx-1
if 'z' in keylog.map:
if keylog.map['z']: (fire,bullety,bulletx)=(True,shipy,shipx)
if shipy<0: shipy=0
if shipy>my-len(ship): shipy=my-len(ship)
if shipx<0: shipx=0
if shipx>mx-len(ship[0]): shipx=mx-len(ship[0])
if fire and bullety == 0: fire=False
if fire: bullety=bullety-1
s.erase()
s.addstr(shipy,shipx,ship[0])
s.addstr(shipy+1,shipx,ship[1])
try:
s.addstr(shipy+2,shipx,ship[2])
except error: pass
if fire: s.addstr(bullety,bulletx,bullet)
s.refresh()
napms(10)
wrapper(main)
Offline
haha, too bad it lags a little, and need sudo to run. I succeeded in crashing it, here's the output if you want =p
Traceback (most recent call last):
File "./game", line 86, in <module>
wrapper(main)
File "/usr/lib/python2.6/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "./game", line 80, in main
if fire: s.addstr(bullety,bulletx,bullet)
_curses.error: addstr() returned ERR
I happens when you hold the fire button and go out of the screen up or to the left.
It also freezes randomly =p
Offline
Hah yeah, those bugs should be easy to fix, but the 10 ms sleep probably isn't a good game routine. I'm going to leave it at that though...
Offline
Maybe it's because I have a USB keyboard, but when I tried this again it wasn't working anymore.
The length of a key event is now 1.5x bigger (it took me a while to find out - or maybe I was wrong all along)
Data collection:
sudo hexdump -e '72/1 "%x " "\n"' /dev/input/event0
Here is an example script that doesn't use a keyboard map, but just checks to see if there are any keys currently depressed, and if so turn on a LED (I have a new laptop and I am using this right now, however I could only find one single LED to use, and it's tiny, shared by hard disk usage and exactly where you would put your left wrist - search for LEDs continues, because this seems quite fun to use)
#! /usr/bin/python
import sys,signal
#config
LED=open("/sys/class/leds/hp::hddprotect/brightness",'w')
KBD=open("/dev/input/event0",'rb')
def clean(un,used):
ledwrite("0")
sys.exit(0)
signal.signal(signal.SIGTERM, clean)
signal.signal(signal.SIGINT, clean)
signal.signal(signal.SIGHUP, clean)
signal.signal(signal.SIGQUIT, clean)
def ledwrite(state):
LED.write(state)
LED.flush()
count=0
while True:
event=KBD.read(72)
if event[44] == '\x01':
if count == 0:
ledwrite("1")
count+=1
elif event[44] == '\x00':
count-=1
if count == 0:
ledwrite("0")
if count < 0:
count = 0
ledwrite("0")
Offline
What is the reason for that? Isn't it easier to just look at your fingers?
Offline