linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: question about gcc and keyboard hadling
Date: Tue, 6 Aug 2002 08:13:33 +0200	[thread overview]
Message-ID: <20020806061333.GO758@lug-owl.de> (raw)
In-Reply-To: <15694.36614.996185.222692@cerise.nosuchdomain.co.uk>

[-- Attachment #1: Type: text/plain, Size: 1945 bytes --]

On Mon, 2002-08-05 15:43:18 +0100, Glynn Clements <glynn.clements@virgin.net>
wrote in message <15694.36614.996185.222692@cerise.nosuchdomain.co.uk>:
> 
> +Rudymartin wrote:
> 
> > im trying to develop a text editor using gcc version 2.96 20000731 (Red Hat 
> > Linux 7.1 2.96-81) , and thats because I want to make some experience with 
> > C++ (I used to program in Java and C under windowz) The Info pages have 
> > information about most libraries and functions but I have found no way to 
> > trap the modifiers keys (ALT/CTRL/SHIFT) under a terminal. And I noticed 
> > emacs can trap those keys under a terminal.
> 
> You can't get the same kind of modifier behaviour on a terminal that
> you can in a windowed environment.

Well... It's not exactly portable, but you (at least) can get Ctrl, Alt
and Shift running Linux at the Console. I don't know in which way this
interacts with ncurses (definitely, it _will_ interact on input), but
you can do eg.:

#include <stdio.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <possibly/others.h>

struct termios tio_old;
struct termios tio_new;
int old_mode;
char one_byte;

fd=open("/dev/tty", O_RDONLY);
tcgetattr(fd, &tio_old);
tcgetattr(fd, &tio_new);
ioctl(fd, KDGKBMODE, &old_mode);
ioctl(fd, KDSKBMODE, K_MEDIUMRAW);
tio_new.c_lflag	&= ~(ICANON|ECHO|ISIG);
tio_new.c_iflag = 0;
tio_new.c_cc[VMIN] = 1;
tio_new.c_cc[VTIME] = 1
tcsetattr(fd, TCSANOW, &tio_new);
tcflush(fd, TCIOFLUSH);

while(read() == sizeof(one_byte)) {
	/* Process Input, will show Alt, Shift and Ctrl*/;
	if(dont_need_to_do_more_work)
		break;
}

ioctl(fd, KDSKBMODE, old_mode);
tcsetattr(fd, TCSANOW, &tio_old);
tcflush(fd, TCIOFLUSH);

close(fd);

However - not easily portable:-(

MfG, JBG

-- 
Jan-Benedict Glaw   .   jbglaw@lug-owl.de   .   +49-172-7608481
	 -- New APT-Proxy written in shell script --
	   http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2002-08-06  6:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-05  7:25 question about gcc and keyboard hadling +Rudymartin
2002-08-05 14:43 ` Glynn Clements
2002-08-06  6:13   ` Jan-Benedict Glaw [this message]
2002-08-06  6:19   ` Jan-Benedict Glaw
2002-08-06 16:22     ` Glynn Clements
2002-08-06 18:08       ` About combined console/X11 programs (was: question about gcc and keyboard hadling) Jan-Benedict Glaw
2002-08-06 22:07         ` Glynn Clements
2002-08-07  1:48           ` +Rudymartin
2002-08-07 12:00             ` Glynn Clements
2002-08-07 13:30               ` About combined console/X11 programs Jan-Benedict Glaw
2002-08-07 22:32                 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020806061333.GO758@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).