?
Solved

Pressing keyboard - newbie

Posted on 2003-03-21
3
Medium Priority
?
247 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
[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
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

Independent Software Vendors: 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

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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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