Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-08-2013, 08:14 PM   #1
LQ Newbie
Registered: Oct 2013
Location: Ottawa, IL
Distribution: Wheezy (Debian)
Posts: 7
Blog Entries: 1

Rep: Reputation: Disabled
Disable or Redirect keystrokes from keyboard

This is my 1st post! yay.

I need help quickly. I need to disable/prevent/redirect the output from some keyboard devices in /dev/input/by-path/...
Reason to disable output: these are USB Proximity readers that appear as a keyboard to Linux. Since I'm reading the data into my C program directly from the device using the read() call. I do not want the characters to show up on the monitor.
The real keyboard should still work though.

I can give more detail if needed.

Any help at all would be greatly accepted.

Last edited by RaspPi; 10-08-2013 at 08:50 PM. Reason: make issue easier to understand
Old 10-08-2013, 09:38 PM   #2
LQ Newbie
Registered: Oct 2013
Location: Ottawa, IL
Distribution: Wheezy (Debian)
Posts: 7
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Found solution

ok, I ended up finding the solution. It was as simple as making an IOCtl(xxx,EVIOCGRAB,1) call to get exclusive access to the device.

Here's the full code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>
#include <signal.h>

int main(int argc, char* argv[])
struct input_event ev[64];
int fevdev = -1;
int result = 0;
int size = sizeof(struct input_event);
int rd;
int value;
char name[256] = "Unknown";
char *device = "/dev/input/event0";

fevdev = open(device, O_RDONLY);
if (fevdev == -1) {
printf("Failed to open event device.\n");

result = ioctl(fevdev, EVIOCGNAME(sizeof(name)), name);
printf ("Reading From : %s (%s)\n", device, name);

printf("Getting exclusive access: ");
result = ioctl(fevdev, EVIOCGRAB, 1);
printf("%s\n", (result == 0) ? "SUCCESS" : "FAILURE");

while (1)
if ((rd = read(fevdev, ev, size * 64)) < size) {

value = ev[0].value;

if (value != ' ' && ev[1].value == 1 && ev[1].type == 1) {
printf ("Code[%d]\n", (ev[1].code));

result = ioctl(fevdev, EVIOCGRAB, 1);
return 0;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Distinguish keystrokes from wireless and wired keyboard from script josvanr Linux - Hardware 1 08-26-2013 02:48 AM
Help me log keystrokes on my USB keyboard? Arancaytar Linux - Software 1 03-04-2009 05:11 PM
ps/2 keyboard -> usb connector generating spurious keystrokes on suse 9.3 Thespian Linux - Hardware 6 03-13-2006 05:41 PM
some keystrokes of Logitech LX700 Multimedia keyboard not detected vinayreddy Linux - Hardware 0 12-05-2005 10:30 AM
Keyboard lags for 2-4 keystrokes?! gundelgauk Linux - Hardware 1 05-04-2004 12:53 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 PM.

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