-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_key.c
More file actions
73 lines (51 loc) · 1.35 KB
/
get_key.c
File metadata and controls
73 lines (51 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <linux/types.h>
#include <linux/module.h>
#include <linux/keyboard.h>
#include <linux/input.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
static char str[64];
static int hello_proc_show(struct seq_file *m,void *v)
{
seq_printf(m,str);
return 0;
}
static int hello_proc_open(struct inode *inode,struct file *file)
{
return single_open(file,hello_proc_show,NULL);
}
int kbd_notifier(struct notifier_block *nblock,unsigned long code,void* _param)
{
struct keyboard_notifier_param *param = _param;
snprintf(str,64,"type:%ld value:%d actions: %s",code,param->value,(param->down ? "down" : "up"));
return NOTIFY_OK;
}
struct notifier_block nb =
{
.notifier_call = kbd_notifier
};
static const struct file_operations hello_proc_fops =
{
.owner = THIS_MODULE,
.open = hello_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __init func_init(void)
{
printk(KERN_INFO "get_key init\n");
proc_create("get_key",0,NULL,&hello_proc_fops);
register_keyboard_notifier(&nb);
return 0;
}
static void __exit func_exit(void)
{
remove_proc_entry("get_key",NULL);
unregister_keyboard_notifier(&nb);
printk(KERN_INFO "get_key exited\n");
}
MODULE_LICENSE("GPL");
module_init(func_init);
module_exit(func_exit);