Advertisement

Input response

Started by November 05, 2002 07:18 PM
1 comment, last by CompuWizJacob 22 years ago
How would you make it so the computer takes in and processes a key right after its pressed, instead of the user having to push ? Example: There is a menu like this: new load exit What would you like to do?: Say, the user pushed . The computer responds instantly and opens a new file.
Are you using just plain C++, no Windows?
Nick
Advertisement
There''s a lot of ways to do this, all depending on what you''re using. Although you seem to be using the console, since you mentionned text menus.

If memory serves right, you''d have to use Getch() (stdlib.h methinks).

In the case of Windows programming with no window at all, you can try GetAsyncKeyState();

if(!(GetAsyncKeyState(27) & 0x8000))
{
//the escape key is being held down
}
if(GetAsyncKeyState(27) & 0x8000)
{
//the escape key isn''t being held down
}

This was all done from memory though I''m pretty sure it''s mostly accurate. At worse I might have gotten the ! in GetAsyncKeyState reversed.

This topic is closed to new replies.

Advertisement