Computing.Net > Forums > Programming > c question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

c question

Reply to Message Icon

Name: Posickle
Date: June 11, 2002 at 18:24:32 Pacific
Comment:

how do i make the c program run a function as soon as a button is pressed.

for example, "Press any key when ready"
how do i make that work without pressing an enter key ?

i use inkey$ in Qbasic.. i dont know how i do this in c



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff J
Date: June 11, 2002 at 19:41:35 Pacific
Reply:

If you're talking about a console app, then you just need to use getch()...

printf("Press any key to continue...");
getch();
//rest of code will run after
//a key is pressed

In VC, it's defined as _getch(). Unlike getchar(), it won't make the key's character visible, if it could be.


0

Response Number 2
Name: John W. Borelli
Date: June 11, 2002 at 21:27:26 Pacific
Reply:

Jeff is, of course, correct. Also, if you need the keyboard or other events to be visible during the waiting for a keypress (i.e. special function keys or mouse clicks) then use the KeyPressed function which returnes a boolean value as true when the keyboard buffer has data and false when the keyboard buffer is empty. This function does this WITHOUT extracting bytes from the keyboard buffer. This way, you can have the key test routine in a loop that can also still check for special events (for example with a case statement block) that may occur while your are waiting for any other key press to continue.

borelli33


0

Response Number 3
Name: nadeem
Date: June 12, 2002 at 03:30:44 Pacific
Reply:

try using the kbhit(); function

suppose your function is abc();

try

if(kbhit())
{
abc();
}


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


USB with VB desktop.ini



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c question

C++ question(s) www.computing.net/answers/programming/c-questions/8642.html

A few C++ questions www.computing.net/answers/programming/a-few-c-questions/13898.html

c++ question... www.computing.net/answers/programming/c-question/3127.html