Listing 9. Sample Data Write Function

struct input_event ev; /* the event */

/* we turn off all the LEDs to start */
ev.type = EV_LED;
ev.code = LED_CAPSL;
ev.value = 0;
retval = write(fd, &ev, sizeof(struct input_event));
ev.code = LED_NUML;
retval = write(fd, &ev, sizeof(struct input_event));
ev.code = LED_SCROLLL;
retval = write(fd, &ev, sizeof(struct input_event));

while (1)
{
    ev.code = LED_CAPSL;
    ev.value = 1;
    write(fd, &ev, sizeof(struct input_event));
    usleep(200000);
    ev.value = 0;
    write(fd, &ev, sizeof(struct input_event));

    ev.code = LED_NUML;
    ev.value = 1;
    write(fd, &ev, sizeof(struct input_event));
    usleep(200000);
    ev.value = 0;
    write(fd, &ev, sizeof(struct input_event));
}