[SOLVED] Linux mouse input doesn't work

[SOLVED] Linux mouse input doesn't work

Postby PeterX » 04 Sep 2021, 21:25

The following Linux C code should wait for two mouse events and then exit. But it hangs and doesn't react to mouse clicks/movements.

{l Code}: {l Select All Code}
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/input.h>

FILE            *mouse_file;
struct input_event      event;

int main()
{
   if(!(mouse_file = fopen("/dev/input/event4", "r")))
      exit(-1);
      
   read(fileno(mouse_file), &event, sizeof(struct input_event));
   fread(&event, sizeof(struct input_event), 1, mouse_file);
   
   return 0;
}

Can you tell me what's wrong?

EDIT: Solved! I use /dev/input/mice instead and it works :)
User avatar
PeterX
 
Posts: 270
Joined: 01 Oct 2020, 21:44

Who is online

Users browsing this forum: No registered users and 1 guest

cron