LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-19-2023, 04:13 PM   #1
mystère
LQ Newbie
 
Registered: Nov 2023
Posts: 1

Rep: Reputation: 0
modify input events before it gets to user space, not working.


Hello,

I'm learning Linux kernel development and am currently experimenting with writing a kernel module. I was wondering how I could process events using my kernel module before it gets to user-space, like cancelling a key press, modifying the pressed key... etc.

I tried multiple approaches that failed and crashed the kernel, and here is the latest code I tried as of for now. Using the kernel even callback, I intercept any input event and am trying to cancel the KEY_A event in this code.

I don't understand what's going wrong and why the kernel requests a hardware restart, as well as why it is not blocking the registration on the user-space.

Code:
/**
 * @brief Gets called whenever an input device event is reported
 * @param handle Handle to the input device
 * @param type Event type (see: <linux/input-event-codes.h>)
 * @param code Event code (see: <linux/input-event-codes.h>)
 * @param value Event value (see: <linux/input-event-codes.h>)
 */
void my_module_event_callback(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
    if (type == EV_KEY) {
        pr_info("my_module: event: type=%u, code=%u, value=%d, dev=%s, phys=%s\n", type, code, value, handle->dev->name, handle->dev->phys);
    }

    if (type == EV_KEY && code == KEY_A && value == 1) {
        input_reset_device(handle->dev);
    }
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
user space profiling events enable parameter behaviour not clear: /sys/kernel/debug/tracing/events/enable reset to X when set to 1 barz_83_LQ Linux - Kernel 1 11-30-2017 07:28 AM
problem with X input events, /dev/input/eventX number changes krazyivan Linux - General 0 12-24-2015 01:48 PM
Send Events from Kernel space to User Space bkankru Linux - Kernel 1 03-04-2011 04:24 PM
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 04:16 AM
Hang on triggering udev events- is there a buildup of events? sonichedgehog Slackware 20 07-11-2008 02:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration