[Ilugc] Re: How to trap key strokes

  • From: dearsaravanan@xxxxxxxxx (Saravanan S)
  • Date: Fri Feb 12 17:18:23 2010

On Sat, Jan 9, 2010 at 12:35 PM, Vijay Kumar wrote:

Saravanan S <dearsaravanan@...> writes:
Hi all,
        I used xmodmap to block few key strokes in my distro.
How to initiate/trigger a key combination like say (Ctrl+Shift+Y) as if
the
user has pressed those keys??

Keystrokes can be fed to the kernel using the uinput subsystem. The uinput
subsystem can be accessed through the device file /dev/uinput. But the
interface
is low-level. A wrapper library called libsuinput
http://codegrove.org/libsuinput/ makes things simpler. The code using the
wrapper library is given below. For the sake of simplicity error handling
code
has been omitted.

#include <suinput.h>

int main(void)
{
 struct input_id id = {BUS_BLUETOOTH, 13, 3, 7};
 int uinput_fd = suinput_open("HelloInput", &id);

 suinput_press(uinput_fd, KEY_LEFTCTRL);
 suinput_press(uinput_fd, KEY_LEFTSHIFT);
 suinput_press(uinput_fd, KEY_Y);

 suinput_release(uinput_fd, KEY_Y);
 suinput_release(uinput_fd, KEY_LEFTSHIFT);
 suinput_release(uinput_fd, KEY_LEFTCTRL);

 return 0;
}

Note: You should have uinput module loaded into the kernel. You should have
sufficient privileges to access the device file.


I could not install libsuinput.
Is there any other way to just trigger a single/a combination of key
stroke(s)???


Saravanan Sundaramoorthy
Red Hat Certified Engineer
+91 99404 32545

Other related posts: