> Hello,
> I am developing a C application that operates a barcode reader. The
> reader hardware uses a PS/2 keyboard interface, with a split cable;
> one for the barcode reader, and one to plug the keyboard into.
> This is being developed under RedHat 6.2, with kernel 2.2.16. The
> problem is how I can open the local physical keyboard directly. I
> can't seem to find any /dev special file that correlates to the
> keyboard, and when I open stdin it seems the kernel always deals with
> the ingress data before handing it to me. For instance, when I hit
> Alt-F2, it changes consoles, instead of letting me read the data
> directly. Is it possible to "cut in front" of the kernel on the stdin
> device, so I can handle the input, and pass it to the kernel for
> normal processing, or drop it, or deal with it myself.
> Thank you,
> Hans Zauner
You have to set the tty and the keyboard into raw
mode. Here are a few lines from a program I wrote
doing something similar.
...
#include <termios.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <linux/vt.h>
...
static struct termios ttysetings;
static void daemon_cleanup()
...
tcsetattr(tty_read_fd,TCSANOW,&ttysetings);
ioctl(tty_read_fd,KDSKBMODE,1);
...
static inline int daemon_init(int flag)
...
tcgetattr(tty_read_fd,&ttysetings);
{
struct termios modified=ttysetings;
modified.c_cflag &= ~HUPCL;
modified.c_iflag &=
~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
modified.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
tcsetattr(tty_read_fd,TCSANOW,&modified);
ioctl(tty_read_fd,KDSKBMODE,K_RAW);
}
...
The above example will not work within X, it requires
a textmode VC. Before you start using this, I suggest
you set up this little alias that might help you if
you accidentially leaves the keyboard in an unusable
state. Two presses on some key (which I don't remember)
will reenable translation.
alias `printf "\0203"`='kbd_mode -a'
--
Kasper Dupont