linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "pei lin" <telent998@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Some questions about linux termios
Date: Sun, 13 Jul 2008 01:24:26 +0800	[thread overview]
Message-ID: <d6b7c4190807121024p27464b5cgd27bce2ecd472055@mail.gmail.com> (raw)

Hi,buddy
   I am puzzled by the linux termios.
    First Question about /dev/tty0 and /dev/tty,this two devices is
the same one?
    When i am in X terminal,as /dev/pts/0 , i do "echo hello >
/dev/pts/0 and echo hello > /dev/tty ", they return the same like that
"hello" on the screen .This means /dev/tty ->/dev/pts/0? But "echo
hello > /dev/tty0",there is nothing on the screen.And when i go to
Init 3 mode ,like /dev/tty1,when i do "echo hello > /dev/tty1 and echo
hello > .dev/tty and echo hello > /dev/tty0" ,They return the same all
print hello on the screen.Do they all point to the /dev/tty1?

    The second Question is that i write a small program to get
keyboard input like below.When i run it in X terminal ,when i press
keyboard it can return but can not get the press and release event.And
in the console,like tty1,it doesn't work .i don't know why.

file : get_keyboard.c

#include <stdio.h>
#include <linux/keyboard.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <termios.h>
#include <unistd.h>
int main()
{
	int fd,len,i;
	struct kbentry entry;
	unsigned char buf[64];
	struct termios  ts,old_ts;	
	char * path;
	path = ttyname(0);
	printf("%s!\n",path);
	fd = open(path, O_RDONLY|O_NOCTTY);
	if(fd < 0){
		printf("open the device error!\n");
	}
	
	printf("fd --- %d!\n",fd);
	
	if (ioctl( fd, KDSKBMODE, K_RAW ) < 0) {
			printf("set mode wrong!\n");
	}
	

	tcgetattr( fd, &old_ts );
	

	   ts = old_ts;
     ts.c_cc[VTIME] = 0;
     ts.c_cc[VMIN] = 1;
     ts.c_lflag &= ~(ICANON|ECHO|ISIG);
     ts.c_iflag = 0;
     tcsetattr( fd, TCSAFLUSH, &ts );

     tcsetpgrp( fd, getpgrp() );


	   entry.kb_table = K_NORMTAB;
     entry.kb_value = 0;
	
	while(1){
		len=read(fd,buf,64);
  	printf("len ========= %d!\n",len);
		for(i =0; i < len;i++){
			entry.kb_index = buf[i];
			if(ioctl(fd,KDGKBENT,&entry)){
			printf("struct entry :%d %d
%d\n",entry.kb_table,entry.kb_index,entry.kb_value);
			if('2' == entry.kb_index){
				tcsetattr( fd, TCSAFLUSH, &old_ts );
				exit(0);
			   }
			}
                                      }
		}
}

             reply	other threads:[~2008-07-12 17:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-12 17:24 pei lin [this message]
2008-07-12 17:34 ` Some questions about linux termios Jonathan Isom

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=d6b7c4190807121024p27464b5cgd27bce2ecd472055@mail.gmail.com \
    --to=telent998@gmail.com \
    --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).