Direct Access and Interception of Keyboard Input (stdin)

Direct Access and Interception of Keyboard Input (stdin)

Post by Hans Zaun » Wed, 27 Jun 2001 21:59:05



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

 
 
 

Direct Access and Interception of Keyboard Input (stdin)

Post by Mathias Grimmberge » Fri, 29 Jun 2001 05:17:52



> 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

AFAIK you can't. No sensible OS will let you do that.

Hmm, actually you could look at the source for showkey(1), this program
displays scancodes from the keyboard. I'm however not shure this is what
you need, probably not as it blocks you from switching consoles and in
fact any input. Might be useful for development/debugging.

Quote:> 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.

Yes, but you must extend the driver in the kernel dealing with the PS/2
keyboard. With whatever showkey(1) does you can't selectively handle
some keycodes and give others to the kernel.

MGri
--

Eat flaming death, evil Micro$oft mongrels!

 
 
 

Direct Access and Interception of Keyboard Input (stdin)

Post by Kasper Dupon » Fri, 29 Jun 2001 23:34:51



> 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

 
 
 

1. Direct Control/Access of Local Keyboard (stdin)

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

2. Official RedHat vs. non-offical...

3. Compaq RAID5 Disk Accesses Interfere With Keyboard/Mouse Input at Console

4. cpufreq: x86 tsc cpufreq notifier

5. Merging keyboard input with serial console input?

6. Hard drive light constantly on.

7. How does keyboard input transmit from keyboard of X Server to application?

8. ARCHIVE tape drive

9. HOW TO RE-DIRECT THE STDIN/STDOUT FOR A PROCESS RUNNING IN THE BACKGROUND

10. Can direct output to a pipe, leaving stdin alone?

11. Re-directing stdin/out to socket.

12. how to tell if stdin (cin) has input WITHOUT BLOCKING?

13. Unbuffered input from stdin