-> On Tue, 29 Sep 1998 04:08:21 +0900,
-> "Niko D. Barli" <[EMAIL PROTECTED]>
-> in message ::: Re: [id-linux] KEYPRESSED/KBHIT() pada GCC ? ::: wrote,
>> >> Ada yg bisa caranya mengetahui kalau ada tombol yang ditekan (pd GCC) ?
>> >>
>> Bisa diakalin pake librarynya curses, contohnya :
>>
>> | #include <curses.h>
>> |
>> | int main(){
>> | WINDOW *w;
>> | int c;
>> |
>> | w = initscr();
>> |
>> | cbreak(); /* no line buffering */
>> | nodelay(w, TRUE); /* make getch call non blocking */
>> |
>> | while(1){
>> | if((c = getch()) != ERR) break; /* if(kbhit()) break; */
>> | }
>> |
>> | endwin();
>> | return 0;
>> | }
>>
>> Jangan lupa link dengan library curses atau ncurses.
>>
>> Mungkin ada yang tahu caranya mengimplementasikan kbhit() dengan
>> standard C library ?
>>
Baru ketemu nih caranya mengganti kbhit() pake standard C library,
nggak jamin benar 100 %, tapi yang pasti "kelihatannya" jalan.
ini contoh programnya.
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
/* How to implement if(kbhit()){ do something } */
int main(){
struct termios old_attr, attr;
int c;
/* save termios old attribute */
if((tcgetattr)(STDIN_FILENO, &old_attr) < 0){
exit(-1);
}
/* set new attribute */
attr = old_attr;
attr.c_lflag &= ~(ICANON | ECHO); /* no buffering and no echoing */
if((tcsetattr)(STDIN_FILENO,TCSAFLUSH,&attr) < 0){
exit(-1);
}
/* get a character */
c = getchar();
/* and restore it back before leaving */
ungetc(c, stdin);
/* restore old attributes */
if((tcsetattr)(STDIN_FILENO,TCSAFLUSH,&old_attr) < 0){
exit(-1);
}
/* do something here */
}
--
Niko D. Barli
[EMAIL PROTECTED]
([EMAIL PROTECTED])
http://www.mtl.t.u-tokyo.ac.jp/~niko
The README says, "Needs Windows 95, NT 4.0 or better".
So I installed it on Linux.
----------------------------------------------------------------------
Unsubscribe: [EMAIL PROTECTED]
Archive: http://www.vlsm.org/linux-archive/
Linux CD: [EMAIL PROTECTED]