Solved

Checking the keyboard status in Unix

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

821 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