delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/19/13:30:35

From: dynasens AT tiac DOT net (Mark Levine)
Subject: Keyboard I/O question
19 Jul 1997 13:30:35 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <3.0.1.32.19970719150900.00932c10.cygnus.gnu-win32@sunspot.tiac.net>
Mime-Version: 1.0
X-Sender: dynasens AT sunspot DOT tiac DOT net
X-Mailer: Windows Eudora Light Version 3.0.1 (32)
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

I am able to run the following code segment to detect when a key is
pressed.  This function seems to return a 0 if a key is not pressed with
the time period, and a 1 if a key is pressed.

What I cant seem to get working is to how to figure out which key was pressed.

Calling getc when a 1 is returned by the code segment below does not return
the key that was press.  It waits for another key which is not what I want
to do.

I am looking for a way to read a key, but only if a key has been pressed.
If no key has been pressed I do not want to wait for one.

Can anyone offer any tips?

Thank you in advance.


#include <sys/socket.h>
#include <sys/time.h>

int kbhit()
{
	FD_SET rfds;
	struct timeval tv;

	FD_ZERO(&rfds);
	FD_SET(0, &rfds);
	tv.tv_sec = 0;
	tv.tv_usec = 0;
	select(1, &rfds, 0, 0, &tv);
	return(FD_ISSET(0, &rfds);
}


************************************************************************
*                                                                      *
*                     Visit Our Web Page at:                           *
*               http://www.tiac.net/users/dynasens                     *
*                                                                      *
*----------------------------------------------------------------------*
*                               |                                      *
* Mark Levine                   | EMAIL: dynasens AT tiac DOT net             *
* DynaSense Consulting Services |                                      *
* Framingham, MA 01701          |                                      *
*                               |                                      *
************************************************************************

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019