You are not logged in.

#1 2013-08-27 12:03:58

skwee
Member
Registered: 2013-08-15
Posts: 41

[C,C++] How to handle raw input from keyboard, mouse without X

Hi there!

I'm interested in in writing an input handler for Linux to be able to handle input without X. For some reason, any Google result gives me example using XInput (such annoying that Linux in our days means Linux Kernel + X server =\ ).

Any ideas or material to read? Thanks!


dotfiles
git pull strings master-of-puppets

Offline

#2 2013-08-27 12:18:03

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,600
Website

Re: [C,C++] How to handle raw input from keyboard, mouse without X

If you're wanting raw events, you should probably read up on the kernel module documentation for the devices, e.g. usbhid, psmouse, synaptics, etc.

A link to get you started:
https://www.kernel.org/doc/Documentatio … /input.txt


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2013-08-27 12:20:08

skwee
Member
Registered: 2013-08-15
Posts: 41

Re: [C,C++] How to handle raw input from keyboard, mouse without X

Thanks for the quick reply!
Maybe I misused the word "raw". I know there is evdev (or udev?) that sort of unifies the events from different devices. Can someone point me in that direction?


dotfiles
git pull strings master-of-puppets

Offline

#4 2013-08-27 12:30:48

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,600
Website

Re: [C,C++] How to handle raw input from keyboard, mouse without X

evdev is a part of Xorg, so I don't think that will be much use to you. The source code is available on the xorg website if you want to look at it though.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2013-08-27 12:35:19

skwee
Member
Registered: 2013-08-15
Posts: 41

Re: [C,C++] How to handle raw input from keyboard, mouse without X

This part was very confusing. At some point I was sure evdev is part of the kernel.

Some there is no unified input access to the kernel apart from querying each device individually?


dotfiles
git pull strings master-of-puppets

Offline

#6 2013-08-27 12:42:54

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,600
Website

Re: [C,C++] How to handle raw input from keyboard, mouse without X

My bad, yes it is a kernel module too, it's described in the first link I posted.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2013-09-12 04:58:35

gsingh93
Member
Registered: 2013-07-19
Posts: 96

Re: [C,C++] How to handle raw input from keyboard, mouse without X

For keyboard input you can use the output from /dev/input/eventX. I have a very simple keylogger that does this, it should be fairly straightforward but you can ask me if you have any questions: https://github.com/gsingh93/simple-key-logger

Offline

#8 2013-09-12 12:09:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [C,C++] How to handle raw input from keyboard, mouse without X

Do you need something as gsingh93 suggests, or are you just writing console/tty programs that need keyboard and mouse input.  The latter is much easier.  Just set a couple term settings to get the raw keyboard input and disable echoing (and/or use ncurses to do this for you) and use something like gpm (and/or ncurses) to handle mouse input.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB