#include #include #include #include #include #include #define PROC_FILE_NAME "kbd_demo" size_t tcount = 0; unsigned long int lasttime; struct notifier_block nb; ssize_t read_proc(struct file* filp, char *buf, size_t count, loff_t *offp){ char message[128]; unsigned long int newtime = jiffies; int calls_per_second = (HZ * tcount) / (newtime - lasttime); tcount = 0; lasttime = newtime; sprintf(message, "Calls Per Second: %d\n", calls_per_second); strcpy(buf, message); return strlen(message); } struct file_operations pfo = { read : read_proc, write: 0 }; int kb_notifier_fn(struct notifier_block *nb, unsigned long action, void* data){ struct keyboard_notifier_param *kp = (struct keyboard_notifier_param*)data; printk("action = %lu Key: %d Lights: %d Shiftmap: %x Down: %d \n", action, kp->value, kp->ledstate, kp->shift, kp->down); if(action == 1 && kp->down) tcount++; return 0; } int init (void) { nb.notifier_call = kb_notifier_fn; register_keyboard_notifier(&nb); proc_create(PROC_FILE_NAME,0,NULL,&pfo); return 0; } void cleanup(void) { unregister_keyboard_notifier(&nb); remove_proc_entry(PROC_FILE_NAME,NULL); } MODULE_LICENSE("GPL"); module_init(init); module_exit(cleanup);