[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Pressing keyboard - newbie

Posted on 2003-03-21
3
Medium Priority
?
253 Views
Last Modified: 2010-04-15
I need something which finds out if the keyboard has been hit or not. Basically I want the computer to wait for a while (using a for loop), if so and so key has been pressed do this (which can happen more than once in the loop). However I don't want it to wait until a key has been pressed before continuing.. is there any function like this?

my program is something like:

while (alive)
{
 for (i=0; i<1000000; i++)
 {
 if (x has been pressed)
    do this;
 }
 do this;
}
0
Comment
Question by:triplem
3 Comments
 
LVL 6

Accepted Solution

by:
gj62 earned 60 total points
ID: 8185458
If you are on Windows, use if (_kbhit()){}...
0
 

Expert Comment

by:m1k3
ID: 8185468
if you need a specific key (1) to be pressed just use read the key & if it's the one that Ur expectin' then continue or if U just want any key (2) use getch (); will do it...

e.g. (1)
char x;
read (x);
if (x == '1_char_expected') //or use it value in ascii
{
 ...
}

e.g. (2)
if (getch ())
{
 ...
}
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8185598
make use of bioskey() function
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

607 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