I was playing around with nc and I'm discovering how powerful and versatile this tool is. I was wondering how the file /dev/input/mice works because when I do cat /dev/input/mice you see the output, but I am not sure how to play with that.

I have tried an echo "blablabla" > /dev/input/mice thought it was going to change my mouse coords but didn't do anything.

I have seen in a post that you can have a remote mouse with netcat (not sure where I saw it)

So, If I can take the write from /dev/input/mice in a remote PC to a server listening, writing it to his dev/input/mice ¿?

My idea is:

Server : nc -l -p 6000 > /dev/input/mice

Client : nc <IP> 6000 < /dev/input/mice

I think that that wouldn't work, so does anyone knows how to perform this and explain it a little bit¿? Thank you in advance

  • Do I correctly understand that you want to control your mouse from terminal?
    – jimmij
    Commented Dec 16, 2014 at 12:47
  • I want to control my mouse from another computer, sending the coords through netcat and writing them into the file that handles them.
    – aDoN
    Commented Dec 16, 2014 at 19:22

2 Answers 2


I wrote a more detailed answer to essentially the same question there, but the main idea is:

Client: nc -l -p 4567 | uinput

Server: intercept -g /dev/input/by-id/usb-My-mouse-name | nc 4567

This uses Interception tools - A minimal composable infrastructure on top of libudev and libevdev


Raw handling of mouse events using a device file would require :

  1. elevated privileges such that you should not expose to a client application
  2. enough knowledge of the inner workings of the mouse device, to basically build your own mouse driver, which of course could be a loadable kernel module and it could be made accessible via a local service of your own creation that would receive commands from the network and send them to the kernel module over a custom protocol, or
  3. you could simply make an application that exposes the functionality of the loaded mouse driver to some sort of external network interface, in which case the simplest solution for the client would be to make it a REST interface and operate it via either curl or a browser

But none of the above solutions seem safe...

Fortunately there are tools that would spare you from such a painstaking effort... and provide you with a safe solution to your problem.

I suppose that when you say that, "you want to control the mouse remotely", you mean to control the mouse as displayed in the target graphical user interface. This is a service provided by the X-Windows server and can be easily and safely controlled via command line using ssh.
Excuse me but, I really do not know how netcat fits into this picture...

So what you could do is simply use the xdotool to simulate a mouse event over an ssh connection with:

$ ssh user@machine xdotool mousemove 0 0 click 1

Yes, it is really that simple!

How do mouse events work in linux?

That is in case, you want to control the mouse cursor as seen in the target operating system. Because if your goal is to create a terminal application that uses the mouse (this is the mouse that is physically attached to the client) then you should definitely go for a program that is based on ncurses. ncurses makes use of an open source terminal mouse server and can also be used to provide an elaborate gui interface all over ssh and a simple terminal. Also, ncurses does not depend on x-server running, because it does not affect the server's mouse in any manner, it simply uses the client's mouse to control the application.

In any case, if your goal is to simply play with linux device files, try sending a document to the audio device and see how it sounds... a simple cat and pipe with root privileges will work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .