i have this code to determine which lights are on, on a keyboard.
but if i run it in x windows it doesn't work, i get the error
Code:
ioctl: Invalid Argument
but if i press ctrl+alt+f1 for example the code will work in one of these terminals fine.
is there a way to get it to work in x windows, or is ioctl limited to terminals ??
here is the code
Code:
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/kd.h> /* Keyboard IOCTLs */
#include <sys/ioctl.h> /* ioctl() */
#include <sys/types.h>
#define ERROR -1
void checkleds();
long int arg;
int main()
{
int fd; /* Console fd (/dev/tty). Used as fd in ioctl() */
//long int arg; /* Where the LED states will be put into. */
/* To use as the fd in ioctl(). */
if ((fd = open("/dev/tty", O_NOCTTY)) == ERROR) {
perror("open");
exit(ERROR);
}
printf("first %d\n" , arg);
/* Value stored in arg. */
if (ioctl(fd, KDGETLED,&arg) == ERROR) {
perror("ioctl");
printf("%d\n", arg);
close(fd);
exit(ERROR);
}
/* Here we print out current LEDS. */
checkleds();
}
void checkleds()
{
/* LED_SCR = 0x1, LED_NUM = 0x2, LED_CAP = 0x4 */
if (arg == LED_SCR) printf("Scroll Lock LED is on.\n");
else if (arg == LED_NUM) printf("Numeric Lock LED is on.\n");
else if (arg == LED_CAP) printf("Caps Lock LED is on.\n");
else if (arg == LED_NUM + LED_CAP)
printf("Numeric Lock and Caps Lock LEDs are on.\n");
else if (arg == LED_NUM + LED_SCR)
printf("Numeric Lock and Scroll Lock LEDs are on.\n");
else if (arg == LED_CAP + LED_SCR)
printf("Caps Lock and Scroll Lock LEDs are on.\n");
else if (arg == LED_NUM + LED_SCR + LED_CAP)
printf("Numeric Lock, Scroll Lock, and Caps Lock LEDs are on.\n");
else if (arg == 0)
printf("No LEDs are on. \n");
}
thanks for any help in this matter