| USB HID for Linux USB | ||
|---|---|---|
| <<< Previous | The event interface | Next >>> |
While input devices don't normally have a lot of data sent to them, there are certain situations where it is useful. For example, a keyboard might have LEDs, or perhaps a buzzer, to indicate mode or error conditions. This section looks at how to send information to an input device.
Sending information to the device is done using the write function call on the event interface. This function call takes a input_device structure. The time element is not used. The type is the type of event that is being sent out (for example, EV_LED, EV_SND, EV_REP or EV_FF). The code is the particular feature that is being manipulated (for example, LED_NUML, LED_CAPSL, REP_DELAY or SND_BELL. The value is the value to set the particular feature to.
Lets look at an example of the write function. This example manipulates the LEDs that are provided on most keyboards and some gamepads.
![]() | About this example |
|---|---|
This example is intentionally a code fragment, and is not complete, nor is it meant to show good programming style. A complete form of this example (that will compile with gcc -Wall -W) is provided in the second part of this document. |
Example 8. write example
struct input_event ev;
…
ev.type = EV_LED;
ev.code = LED_CAPSL;
ev.value = 1;
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)); |
| <<< Previous | Home | Next >>> |
| Getting user input from the device | Up | Modifying key repeat settings |