HID input on linux for games - linux

What is the best way to capture HID input on linux for games? I don't need anything special. Just mouse and keyboard. Right now I'm using Xlib. I have a separate input thread, which has its own connection to the X Server (Display instance) and it handles events for main render window. It is working just fine, but it is a bit limited. For example, I'm missing mouse raw input.

Have you tried opening and reading device files in /dev/input?

Related

Are there X11 XInput2 raw events for joysticks and controllers?

I am using the XInput2 interface in C++ to get raw input events for keyboard and mouse on my X11 application to linux. That works fine.
I have a joystick and a bluetooth connected game controller (xbox controller like)
I don't see any events from either of those using XInput2
Should I expect to be able to get events from those as well as keyboard & mouse or is there a different method I should use for them?
A brief look seems to indicate that I can use read events from /dev/input/event* for them. Is this the correct way to interface with them in low level linux. That seems a pity as I'll need two entirely different input event systems, one for keyboard & mouse, and one for controller and joystick so wanted to make sure before going that way.

Epson projector

I have a projector that can accept control commands like turn on/off and queries like amount of time it was on.
Control commands work, but I can't seem to capture responses from queries; when I connect via USB, I get two additional raw input files in the dev directory.
I wrote a C program that captures events from input devices it captures mouse movements and keyboard events, but it doesn't capture replies from the projector at all, not even the event itself. Why is that?
In Windows, everything works.

Datalogic Scanner-Write Data to File

I have a Datalogic PM8300-DK Scanner that is working fine so far. I choose the USB-KBD-Mode (USB INTERFACE SELECTION) and now everytime I scan a barcode, the data-representation of the barcode is writen on my computer (where the cradle is connected to).
But the problem is, the data is writen to where the cursor stands (where the focus is). For example, when the focus is in a text-editor, the scanner writes the data to the text-editor. When the focus is in the google-search-box of my browser, it writes the barcodes to the search-box.
I would prefer if the data would be writen directly to a file, and there would be no output to the screen directly. Is that possible, does anyone know a modus for that ?
Thanks, Andre
You need to use the serial or USB serial emulation (COM port) connection for that. You will also need to have some software to handle the data.

Use serial-console as display, but computer keyboard for standard-input

I have a 40x7 VFD that functions as a serial terminal. It has a dedicated keypad that provides hex-entry, however, I would like to use a keyboard for the standard input. Basically, I want to be able to use the VFD as a display for a Linux bash prompt, but use the keyboard connected to the computer as the means of input. Instead of connecting a monitor, the serial terminal will be the monitor. I can get the login prompt displayed on the VFD with agetty, but since it only has hex-entry, how can I change where the system is looking for standard input?
Thanks,
Core_Module
I think the best method would be to create a pseudo terminal. In doing so you create a fake terminal device with a /dev/pts/[n] name that acts like a real input/output device. A program could connect the console (keyboard) as input and the VFD as output and send and receive that data over the pseudo device. You can then point agetty at the /dev/pts/[0] device instead of a /dev/ttyS[n] device. Some ideas on doing this can be found in many tutorials online. From the link:
A pseudo-terminal is a pair of character mode devices also called pty. One is master and the other is slave and they are connected with a bidirectional channel. Any data written on the slave side is forwarded to the output of the master side. Conversely, any data written on the master side is forwarded to the output of the slave.
I found another StackOverflow question that may also be of assistance. See this link. It could be adapted to suit your needs.

How to read from STDIN_FILENO even if terminal is closed?

Im trying to code a program in Linux to read every input from keyboard, but using STDIN_FILENO it only reads those entered in the terminal. What I want is during execution it should read keyboard even if the terminal is closed.
STDIN_FILENO is just a helper macro.
From stdin you recieve stream of bytes that are passed to your program, they doesnt neccessary come from terminal - also can from a file, etc. It's not capturing keyboard. The terminal is capturing keyboard and then passes entered data to your program's stdin.
In order to capture keyboard you will need some other method of receiving events. I guess you are running GUI aka X server; Normally applications create windows and receive events related to them. In order to capture all keyboard events, you will have to go more low-level. Take a look at xlib which should be sufficient for you, even though it might not be.

Resources