T
T
Timur2016-02-26 22:05:55
linux
Timur, 2016-02-26 22:05:55

How to catch and count mousemove events in bash in ubuntu?

I've been fighting for several hours, I can not understand what's what. I need to write a bash script on the ubuntu desktop that will be run by cron every minute, and send a post request to my script that the mouse was moved on the computer or the buttons on the keyboard were pressed.
And I got stuck at the very beginning. I can not normally catch these events. Ubuntu 14.04, installed input-events executing code

$ sudo /usr/bin/input-events 5
/dev/input/event5
   bustype : BUS_PCI
   vendor  : 0x80ee
   product : 0xcafe
   version : 1027
   name    : "VirtualBox mouse integration"
   bits ev : EV_SYN EV_KEY EV_ABS

waiting for events
22:01:12.603834: EV_ABS ABS_X 21648
22:01:12.603834: EV_ABS ABS_Y 39061
22:01:12.603834: EV_SYN code=0 value=0
22:01:12.611939: EV_ABS ABS_X 21580
22:01:12.611939: EV_SYN code=0 value=0
22:01:12.622667: EV_ABS ABS_X 21512
22:01:12.622667: EV_SYN code=0 value=0
22:01:12.627384: EV_ABS ABS_X 21478
22:01:12.627384: EV_SYN code=0 value=0
22:01:12.635220: EV_ABS ABS_X 21443
22:01:12.635220: EV_SYN code=0 value=0
22:01:12.647422: EV_ABS ABS_X 21375
22:01:12.647422: EV_SYN code=0 value=0
22:01:12.652264: EV_ABS ABS_X 21341
22:01:12.652264: EV_SYN code=0 value=0
22:01:12.659410: EV_ABS ABS_X 21307
22:01:12.659410: EV_SYN code=0 value=0
22:01:12.667808: EV_ABS ABS_Y 39006
22:01:12.667808: EV_SYN code=0 value=0
22:01:12.675614: EV_ABS ABS_X 21273
22:01:12.675614: EV_SYN code=0 value=0
22:01:12.700349: EV_ABS ABS_X 21239
22:01:12.700349: EV_SYN code=0 value=0

everything is fine. I'm trying to count the events (already as soon as I tried it) - it doesn't work. The most banal:
$ sudo timeout 10 "/usr/bin/inputvents" 5 | wc -l
displays the number of lines only if I drive the mouse sooooo much. If the movements are not significant (a hundred or two pixels), 0 is always returned. Although simply executing the sudo /usr/bin/input-events 5 command reacts even to mouse movements of one pixel
Why is this happening? Help me figure it out and find a solution
upd: I don't need to make a keylogger, but just check the fact of pressing any buttons on the keyboard. Those. need to know what is being printed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
onlooked, 2016-02-27
@onlooked

There is a console snail "xdotool". The documentation is more than clear. There are also articles on it on Habré.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question