Solved

Checking the keyboard status in Unix

Posted on 1997-09-16
2
257 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

739 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