Solved

Checking the keyboard status in Unix

Posted on 1997-09-16
2
258 Views
Last Modified: 2006-11-17
Which function in Linux C can you use to check to see whether or not a keystroke is pending?  And more importantly, how can I use this function?
0
Comment
Question by:Hexar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
msmits earned 200 total points
ID: 1254745
You should use the ioctl() system call on the file descriptor of the stdin.
On SUN Solaris, the manual page refers to the termio(7I) manual page which has a section about non-canonical mode input processing, which is what you want.
I believe I have some old code somewhere in which I did something like thing. I will try to find that for you, although it may use an older interface.

0
 
LVL 3

Expert Comment

by:msmits
ID: 1254746
#include <sys/ioctl.h>
#define fileno(p) ((p)->fd)

bool keypressed()
/* test whether a key if pressed */
{
      long l;
      int fd;

      fd = fileno(stdin);

      if (ioctl(fd, FIONREAD, &l) != -1)
            if (l > 0)
                  return TRUE;
      return FALSE;
}

0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question