[LINUX:22748] LINUX C DE KBHIT VE GETCHE

---------

New Message Reply About this list Date view Thread view Subject view Author view

From: olcay ors (ocors@yahoo.com)
Date: Sat 09 Dec 2000 - 10:47:54 EET


LINUX ILE C PROGRAMI YAPARKEN ENCOK KARSILASTIGIM
SORUN DOS DAKI KBHIT() VE GETCHE() KOMUTLARIYDI
ARAMADA ASAGIDAKI ALT PROGRAMLARI BULDUM ILGILENEN
ARKADASLARA FAYDASI OLACAGI DUSUNCESIYLE

-- start of code snippet
#include <stdio.h>
#include <termios.h>

static struct termios orig, new;
static int peek = -1;

int main()
{
  int ch =0;

  tcgetattr(0, &orig);
  new = orig;
  new.c_lflag &= ~ICANON;
  new.c_lflag &= ~ECHO;
  new.c_lflag &= ~ISIG;
  new.c_cc[VMIN] = 1;
  new.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &new);

  while(ch != 'q') {
    printf("looping\n");
    sleep(1);
    if(kbhit()) {
        ch = readch();
        printf("you hit %c\n",ch);
    }
  }

  tcsetattr(0,TCSANOW, &orig);
  exit(0);

}

int kbhit()
{

  char ch;
  int nread;

  if(peek != -1) return 1;
  new.c_cc[VMIN]=0;
  tcsetattr(0, TCSANOW, &new);
  nread = read(0,&ch,1);
  new.c_cc[VMIN]=1;
  tcsetattr(0, TCSANOW, &new);

  if(nread == 1) {
   peek = ch;
   return 1;
  }

  return 0;
}

int readch()
{

  char ch;

  if(peek != -1) {
    ch = peek;
    peek = -1;
    return ch;
  }

  read(0,&ch,1);
  return ch;
}
-- end of code snippet

BASARILAR
SEVGILER
SAYGILAR

OLCAY ORS

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/

 
 Listeden cikmak icin:
          unsub linux
 mesajini listeci@bilkent.edu.tr adresine gonderiniz.
   Lutfen Listeci icin MIME / HTML / Turkce Aksan kullanmayin.
 Listeci arayuzu: http://listweb.bilkent.edu.tr/yardim/bilkent/linux.html
 Liste arsivinin adresi: http://listweb.bilkent.edu.tr/


New Message Reply About this list Date view Thread view Subject view Author view

---------

Bu arsiv hypermail 2b29 tarafindan uretilmistir.