0

As far as I know, in Linux, inputs from hardware devices can be thought as writing data to files, so I think that it is quite possible to write something to /dev/input/mice for simulating mouse click without using X.

This is what I have done:

root@linux:~$ sudo cat /dev/input/mice >> right-click
(click the right button of your mouse, and then press ctrl+c to terminate it.)
root@linux:~$ sudo cat right-click >> /dev/input/mice

I did this for testing whether writing something to /dev/input/mice can simulate mouse click or not, but obviously it failed. Any reasons?

Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
  • There is a tool for same purpose `xdotool` and here is some [uses](http://tuxradar.com/content/xdotool-script-your-mouse) [sample](http://xmodulo.com/simulate-key-press-mouse-movement-linux.html) – Arnab Nandy Jan 10 '15 at 07:15
  • Possible duplicate: [Control mouse by writing to /dev/input/mice](http://stackoverflow.com/questions/20595716/control-mouse-by-writing-to-dev-input-mice) – augurar Jan 10 '15 at 07:48

1 Answers1

1

The reasons that writing to a device fails is that the kernel mouse driver does not take bytes from the device file and send them back to the device file.

Suppose you had a serial mouse. Writing bytes to a serial port, would you expect to read those bytes back from the same serial port? Bytes written to a device file might be read by the device, they should not be expected to be readable back from the device file.

Henrik Carlqvist
  • 1,138
  • 5
  • 6