kbhit() 유사한 함수가 있나요?

익명 사용자의 이미지

윈도우에서 console 상에서 프로그램 할때 쓰던 kbhit() 라는 함수와 유사한
게 리눅스에도 있나요?

console 상에서 비동기 입력을 처리할려면 어떻게 하는게 좋을까요? RETURN 키
가 눌려지지 않아도 입력될 수 있으면서요...

익명 사용자의 이미지

curses 라이브러리가 있습니다.

리눅스에서는 ncurses.h libncurses.a 또는 libncurses.so 일 겁니다.

익명 사용자의 이미지

nodelay 를 TRUE 로 하고 getch 를 씁니다.
옛날에 해 본 예제인데, 돌아갈 지 모르겠네요.
지금 NT 부팅 중이라 테스트 못해보고 그냥 올립니다.
그냥... 짧은 프로그램이니... 참고하시길.

#include
#include

int main( void )
{
WINDOW* w = initscr();
nodelay ( w, TRUE );
while( getch()!='q' ) {
echochar( 'A' );
}
endwin();
return 0;
}

익명 사용자의 이미지

..

익명 사용자의 이미지

어쩌다 보니 자문자답하게 됬네여... ncurses 을 안쓰고 할 수있는 방법이 있
나 고민해 보다...아래와 같이 작성했는데 되네요... 근데..만들어 놓고 생각
해보니.. 체스맨님이 써준것이 훨씬 간단하고 깔끔하네요... 누군가 말했듯이
바퀴를 다시 만들 필요도 없는건데... 어째든.. 혹시.. ncurses 안 쓰고
kbhit 을 구현하고 싶은신 분 사용하세요.. .참고로 Begining Linux
Programming 의 있는 내용을 사정없이 요약해서 테스트한 것입니다. 그럼 이
만...

struct termios old_t, new_t;

tcgetattr( fileno(stdin), &old_t );
new_t = old_t;
new_t.c_lflag &= ~ICANON;
new_t.c_lflag &= ~ECHO;
new_t.c_cc[VMIN] = 0;
new_t.c_cc[VTIME] = 0;
tcsetattr( fileno(stdin), TCSANOW, &new_t );

count = 100;
while ( count-- > 0 ) {

익명 사용자의 이미지

system 콜로 stty 를 콜해서 콘솔 모드를 바꿀 수도 있습니다.

간편하지만 글쎄.. -_-;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.