Getting device input (mouse, keyboard ...) on LINUX

I am creating a cross-platform game engine, and now I am focused on the input system.

I wrote an abstract input system that passes messages up and is loaded by platform-specific modules working in a separate thread.

In the windows, I created the "Message Only" window, into which the system with messages (translated to a platform independent) from RAWINPUT is fed in.

Now I am having problems figuring out how to do this on a unix based system. Is there a convenient way to get input (keyup, keydown, mousemove ...) from the kernel? Or in any other way without having to display any window?

EDIT

I do not want my input system to depend on my Renderer. Renderer should just notify when the focus of the application has changed ... Therefore, I want the input system to work on a different thread than on the renderer.

+4
source share
3 answers

In the X Window system, there is a concept for window input only, which is more or less parallel to a window for Windows messages only.

0
source

Typically, cross-platform input is achieved using a wrapper library - SDL is good, and the current version is even BSD licensed.

The benefits of using a wrapper are so great that even Windows games that use their own Windows solution usually use SDL as a shell when running on Linux (this was the original reason SDL was created).

In the worst case scenario, you can store your libraries on Windows and use SDL for implementation specifically on * nix systems.

+5
source

Assuming you are using X11:

Peter Hatterer has a series of XInput2 articles . Confirms unprocessed events .

ManyMouse claims to use XInput2 without a window :

  • On Unix systems, we try to use the XInput2 extension, if possible. ManyMouse will try to abandon other approaches if there is no X server or the X server does not support XInput2. If you want to use XInput2, make sure you refer to "-ldl" as we use dlopen () to find the X11 / XInput2 libraries. You do not need to reference Xlib directly, and ManyMouse will fail gracefully (without telling mice in ManyMouse XInput2) if libraries do not exist on the system. Naturally, you will need the X11 headers on your system (on Ubuntu, you would like apt-get install libxi-dev). You can build with SUPPORT_XINPUT2 set to zero to completely disable XInput2 support. Please note: XInput2 target does not require your application to ship X11 windows. The test_manymouse_stdio application works for this purpose while X is running. Note that the X11 DGA extension conflicts with XInput2 (in particular: SDL can use it). This is a good way to handle this in SDL 1.2:

Maybe it's worth a look at the source.

+2
source

Source: https://habr.com/ru/post/1393758/


All Articles