Code: Select all
// Find and open input devices in /dev/input/by-id that end in "event-kbd" and "event-mouse"
// These are then set for exclusive access so mouse and keyboard events are not passed to
// the console ( or X).
if((mouseFd == -1) && (regexec (&mouse, dp->d_name, 0, NULL, 0) == 0))
{
printf("match for the mouse = %s\n",dp->d_name);
sprintf(fullPath,"%s/%s",dirName,dp->d_name);
mouseFd = open(fullPath,O_RDONLY | O_NONBLOCK);
printf("%s Fd = %d\n",fullPath,mouseFd);
printf("Getting exclusive access: ");
result = ioctl(mouseFd, EVIOCGRAB, 1);
printf("%s\n", (result == 0) ? "SUCCESS" : "FAILURE");
}
Code: Select all
ioctl(mouseFd, EVIOCGRAB, 0);
Code: Select all
if((keyboardFd == -1) && (regexec (&kbd, dp->d_name, 0, NULL, 0) == 0))
{
printf("match for the kbd = %s\n",dp->d_name);
sprintf(fullPath,"%s/%s",dirName,dp->d_name);
keyboardFd = open(fullPath,O_RDONLY | O_NONBLOCK);
printf("%s Fd = %d\n",fullPath,keyboardFd);
sleep(1); // Give the shell a chance to see the return key up
//event before grabbing exclusive access.
printf("Getting exclusive access: ");
result = ioctl(keyboardFd, EVIOCGRAB, 1);
printf("%s\n", (result == 0) ? "SUCCESS" : "FAILURE");
}