如何使用Linux驱动程序使键盘LED闪烁?

时间:2013-06-26 19:17:43

标签: c linux keyboard kernel driver

我对Linux驱动程序开发很新。请发布一个代码片段,它将说明linux驱动程序以捕获任何键盘按下,这将使capslk或scrllok或numlok led闪烁。我正在使用内核版本3.5的ubuntu 3。提前谢谢。

1 个答案:

答案 0 :(得分:1)

所有相关信息都可以在Linux内核源代码树文档中找到。最重要的是在$KERNELSRC/Documentation/input/input.txt

5. Event interface
~~~~~~~~~~~~~~~~~~
Should you want to add event device support into any application (X, gpm,
svgalib ...) I <vojtech@ucw.cz> will be happy to provide you any help I
can. Here goes a description of the current state of things, which is going
to be extended, but not changed incompatibly as time goes:

You can use blocking and nonblocking reads, also select() on the
/dev/input/eventX devices, and you'll always get a whole number of input
events on a read. Their layout is:

struct input_event {
  struct timeval time;
  unsigned short type;
  unsigned short code;
  unsigned int value;
};

'time' is the timestamp, it returns the time at which the event happened.
Type is for example EV_REL for relative moment, EV_KEY for a keypress or
release. More types are defined in include/linux/input.h.

'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete
list is in include/linux/input.h.

'value' is the value the event carries. Either a relative change for
EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for
release, 1 for keypress and 2 for autorepeat.

事件代码在中描述 $KERNELSRC/Documentation/input/event-codes.txt

LED有特殊事件代码,您不仅可以从/dev/event…读取,还可以使用LED事件代码写入,以设置LED状态。