How can you track mouse input using smallest libraries in c

I'm not sure where to look for this information, but I would like to know how to get mouse input (or any hidden input) using the smallest non-standard libraries in c. Basically, is there an equivalent to stdio for input (and other input) in c? Or there is a library that is minimal and compatible with the cross on multiple platforms. Just being able to print the coordinates of the mouse in a terminal window will be enough.

+4
source share
3 answers

Here is a 0 non-standard library approach. Executed wherever / dev / input / event # exists.

#include <linux/input.h> #include <fcntl.h> int main(int argc, char **argv) { int fd; if ((fd = open("/dev/input/mice", O_RDONLY)) < 0) { perror("evdev open"); exit(1); } struct input_event ev; while(1) { read(fd, &ev, sizeof(struct input_event)); printf("value %d, type %d, code %d\n",ev.value,ev.type,ev.code); } return 0; } 

On Windows, you need to do something terrible using the Win32 API and connect to the messaging system.

In short, no, there is no standard for this in C.

+2
source

SDL will do the trick I think.

+3
source

Depends on the platform and operating system. If you want to directly track mouse (or HID) events, you may need to write a driver or find it. The driver will control the port and listen for mouse data (messages).

In an event-driven system, you will have to subscribe to mouse event messages. Some operating systems will broadcast messages for each task (for example, Windows), while others will send events only to subscribers.

This is too general a question to get a specific answer.

0
source

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


All Articles