Another thing to watch for ...
If you try to get exclusive access for the keyboard in a similar way, it is important to have a short pause before doing it.
See the comment in the code below.
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");
}
Without "sleep(1)" the shell gets lots of auto repeated return keys as the keyboard driver never see the "key up" event that matches the "key-down" event that started the program.
PeterO