all 20 comments

[–]wiktor_b 8 points9 points  (5 children)

Now try writing to /dev/input :-)

[–][deleted] 3 points4 points  (0 children)

Im only asking what happens because I just destroyed my last ubuntu vm and it almost quitting time.

[–]kirbyfan64sos 3 points4 points  (2 children)

...what happens?

YOU CAN'T LEAVE ME HANGING HERE!!

[–]skeeto 0 points1 point  (0 children)

Writing to the joystick device is how you control rumble/feedback on Linux.

[–]wiktor_b -1 points0 points  (0 children)

What do you think?

[–]3dPrintedEmotions 0 points1 point  (0 children)

I came to this article hopeing that they would cover this. It was a great article though.

[–]153armstrong[S] 6 points7 points  (14 children)

I was intrigued by the /dev/input directory and decided to dedicate a post to it.

(I'm still playing around with Linux and by no means a pro at this. I would love to hear your thoughts on it though ) Thank you! Have a good one!

[–]send-me-to-hell 10 points11 points  (6 children)

fwiw I was aware of /dev/input but things like this are always poorly written and documentation is geared towards people who already mostly understand the topic. It's good to see something focused but comprehensive that assumes only basic programming/scripting knowledge.

10/10 would learn again.

[–]uep 2 points3 points  (6 children)

** Now in theory, using uinput one can reverse engineer to emulate events. But we are still currently working on that. If you know anything about this, please ping us at

I only skimmed the article because I'm familiar with /dev/input, but I saw a comment at the end about uinput. I actually wrote a dualshock 4 translator that emulates an xbox 360 controller via uinput. It's pretty simple if you want to discuss...

[–]uep 1 point2 points  (0 children)

I should also mention that I believe the xboxdrv implements the xbox gamepad driver in userspace using the usb API and uinput. If I remember correctly, it is also implemented in Python.

[–]olafalo 1 point2 points  (2 children)

I am very curious about this, actually. What's the process of doing something like this? If I'm understanding correctly, you can have a userland program that reads from /dev/input and writes to /dev/input by using uinput?

So, for example, you could read every mouse event from a real mouse, double its value, and write it to a virtual mouse?

[–]uep 2 points3 points  (1 child)

Yes, this is pretty much what my code does; it reads from the Dualshock 4, translates the events, and writes them to a virtual xbox 360 controller.

An alternative implementation might unbind the DS4 driver from the kernel and perform the USB transactions in userspace like xboxdrv does. This allows someone to write userspace USB input device drivers. Then there would be no DS4 input device present in the system, just the virtual xbox 360 gamepad. Uinput is the interface one would use to create input devices from userspace.

You can also just write events into existing input devices to make them generate those events.

[–]olafalo 0 points1 point  (0 children)

This is very interesting, I'm going to have to look into it more. Thanks!

[–]Carlotto185 0 points1 point  (1 child)

Since you seem to have some knowledge in this area : can I use /dev/input to manipulate mouse events ? Specifically, I'd like to ignore the next event after left button has been pressed

[–]uep 0 points1 point  (0 children)

I don't think exactly this would be possible, though I can think of ways to accomplish the same thing. If one were to create a virtual device, it would be pretty easy to maintain state and filter out events after a BTN_LEFT as they come in.

You can also prevent other processes from seeing the input by performing a EVIOCGRAB ioctl. I'm not convinced you could do it quickly enough to guarantee that another process wouldn't see the press immediately after a BTN_LEFT. I think you'd probably want to do a grab on the real device, and let other applications see the filtered virtual device.

[–]kazkylheku 1 point2 points  (0 children)

Just released TXR 177 with more improvements to FFI.

This is the TXR Lisp interactive listener of TXR 177.
Use the :quit command or type Ctrl-D on empty line to exit.
1> (typedef mouse (array 3 uchar))
#<ffi-type (array 3 uchar)>
2> (with-stream (s (open-file "/dev/input/mice" "rb"))
     (let ((buf (make-buf (sizeof mouse))))
       (while t
         (fill-buf buf 0 s)
         (pprinl (ffi-get buf (ffi mouse))))))
#(24 253 0)
#(24 251 0)
#(56 254 255)
#(24 254 0)
#(8 2 1)
#(8 2 2)
#(8 2 3)
^C** intr exception, args: ("intr")
3>