我写了一个基本的键盘中断处理程序。它使用共享中断并用于打印到/var/log/messages 哪个键被按下。但是当我尝试使用箭头键时出现以下错误,其余键工作正常。
8 月 19 日 18:59:06 vim 内核:[112.485102] atkbd serio0:释放未知 key (翻译集 2,isa0060/serio0 上的代码 0xe0)。
8 月 19 日 18:59:06 vim 内核:[112.485108] atkbd serio0:使用 'setkeycodes e060' 让它知道。
粘贴代码。
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>
/* This function services keyboard interrupts */
irq_handler_t irq_handler (int irq, void *dev_id, struct pt_regs *regs) {
static unsigned char scancode;
/*
Read keyboard status
*/
scancode = inb (0x60);
if ((scancode == 0x01) || (scancode == 0x81))
{
printk ("You pressed Esc !\n");
}
}
return (irq_handler_t) IRQ_HANDLED;
}
/* Initialize the module and Register the IRQ handler */
static int __init keybrd_int_register(void)
{
int result;
/* Request IRQ 1, the keyboard IRQ */
result = request_irq (1, (irq_handler_t) irq_handler, IRQF_SHARED, "keyboard_stats_irq", (void *)(irq_handler));
if (result)
printk(KERN_INFO "can't get shared interrupt for keyboard\n");
return result;
}
/* Remove the interrupt handler */
static void __exit keybrd_int_unregister(void) {
free_irq(1, (void *)(irq_handler)); /* i can't pass NULL, this is a shared interrupt handler! */
}
MODULE_LICENSE ("GPL");
module_init(keybrd_int_register);
module_exit(keybrd_int_unregister);
谁能给我一些线索,说明为什么当我插入模块并开始工作时,为什么这个箭头键会停止工作,因为我删除了它们?
我在虚拟机上运行我的代码。
最佳答案
原因是由于一些VM搞砸了。它在基本的 linux 主机上运行良好。可以看到代码的完整实现(naive)@https://github.com/vigith/Linux-Device-Drivers/tree/master/keyboard
关于linux-kernel - 编写基本的键盘中断处理程序,抛出 "Unknown key released",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7122392/