gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:22:15 24 4
gpt4 key购买 nike

我对 Linux 驱动程序开发还很陌生。请发布一个代码片段,它将说明 Linux 驱动程序捕获任何键盘按下的情况,并使 capslk 或 scrllok 或 numlok LED 闪烁。我使用的是 ubuntu 3,内核版本为 3.5。提前致谢。

最佳答案

所有相关信息都可以在 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 状态。

关于c - 如何使用 Linux 驱动程序使键盘 LED 闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17328631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com