[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finer keystroke detection

From: Frank Heckenbach
Subject: Re: Finer keystroke detection
Date: Wed, 12 May 2004 00:46:02 +0200
User-agent: semail 20040101

Thomas Dickey wrote:

> On Tue, 11 May 2004, Steve Litt wrote:
> > Hi all,
> >
> > I've looked thru ncurses.h, and through man terminfo, and various other
> > docuemntation, and for the life of me I cannot find how to detect things 
> > like
> > Ctrl+Enter, Ctrl+F3, etc. These would be VERY handy for an app I'm writing.
> > I even wrote a keystroke detection program to print out the value of
> > keystrokes as I type, and according to that program, Enter, Shift+Enter and
> > Ctrl+Enter are identical. According to my program, the alt and Ctrl keys 
> > have
> > no modification effect on function keys etc.
> That's because most terminals send exactly the same escape sequences
> irregardless of the modifiers used.  I know of only a handful of
> exceptions to that.  XFree86 xterm and rxvt implement some; I've noticed
> that gnome-terminal and konsole copied the sequences I added for xterm. A
> few console types (OS/2 for example) also provide different strings. But
> still, most do not.  The standard names in terminfo were based on common
> behavior.  (I'm puzzled by the shifted cursor keys myself - only two of
> the four are defined).
> For the terminal types that do provide this sort of capability, it's
> almost always sufficient to describe those as the numbered function keys
> (terminfo lets you define 60).  Curses can recognize those.  But what
> you're describing is (for instance), Linux console which doesn't supply
> any different strings.
> (If terminals that could do this were more common, it's also possible to
> write extended terminfo entries with ncurses that have more meaningful
> names than f34, f35, etc.

For Linux console you can use ioctl. (That's what I do.)

#include <stdio.h>
#include <sys/ioctl.h>

static int shiftstate ()
  char arg = 6;
  /* replace stdin if you use newterm */
  if (ioctl (fileno (stdin), TIOCLINUX, &arg) < 0)
    return 0;
  return arg;

int main ()
  while (1)
    printf ("%i\n", shiftstate ());

It's more a kludge, though: The state is current at the time you
read it, not the time when the basic key was read. So, especially in
busy situations, a modifier key can be missed or, what's more
confusing, be merged with the previous basic key.

What I'd find ideal is if the keyboard driver could (optionally)
send some escape sequence whenever a modifier key is pressed or
released (i.e., in order with the regular key codes). This could
well be a sequence such as those used for function keys (i.e., 16
special "function keys" which mean press/release of modifier #n).

ncurses might not have to do anything special about them, and the
application would receive them normally and could keep track of
modifiers. This would not have the problems of being asynchronous.
In addition it would work over telnet/ssh etc. Alas, it would
require modifications to the keyboard driver in the kernel ...

(The same could, of course, be done in xterm etc., which wouldn't
need changes in the kernel.)


Frank Heckenbach, address@hidden
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]