Jump to content
  • Advertisement
Sign in to follow this  
Odiee

need something like keypressed

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone knows waht is the func. in c++ that returns 1 or seomthing else when key is pressed. something like:

while(!isKeypressed())
{
 //... do something
}

bool isKeyPressed()
{
 return true;
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Odiee
Does anyone knows waht is the func. in c++


There is none in the Standard C++ Library. You will need to use an external library, such as the Win32 API, SDL, wxWidgets, etc.

Share this post


Link to post
Share on other sites
While there's nothing cross platform in Standard C++, you could use the Win32 API to query a key's state via GetAsyncKeyState().

You could also look into conio.h and make one yourself, but as before, conio.h is not cross platform.
bool KeyPressed( int key )
{
if ( kbhit() )
if ( getch() == key )
return true;

return false;
}


[Edited by - tychon on December 1, 2005 5:18:21 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by tychon
While there's nothing cross platform, you could use the Win32 API to query a key's state via GetAsyncKeyState().

You could also look into conio.h and make one yourself, but as before, conio.h is not cross platform.
bool KeyPressed( int key )
{
if ( kbhit() )
if ( getch() == key )
return true;

return false;
}


Nothing cross platform, ehh? What about SDL? Yes, it is an external library, but it's cross platfor unlike those you mentioned.

C++

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Nothing cross platform, ehh? What about SDL? Yes, it is an external library, but it's cross platfor unlike those you mentioned.

C++


I meant to imply nothing cross platform in Standard C++. Post edited to show this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!