I want to make it so when the user presses the esc or anouther key the p[rogram will do somthing? How do I do that?
I want to make it so when the user presses the esc or anouther key the p[rogram will do somthing? How do I do that?
Part of it depends on specifically what key you want pressed, but mostly it's what type of application you're doing. Is this a Windows app? If so, what API? You'll want to look into event handlers, me thinks.
WinAPI is pretty simple.
Create an array of boolean values of key presses.
but if your not using WinAPI then um.. what are you using.Code:........ bool bKey[255]; ........ // in your message switch do this LRESULT CALLBACK WinProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch ( uMsg ) { case WM_KEYDOWN: bKey [wParam] = true; break; case WM_KEYUP: bKey [wParam] = false; break; } } ........ if ( bKey [VK_ESC] ) PostQuitMessage ( 0 );
With conio..
its probably like
Where KEYS_CODE is the ASCII value.Code:if ( kbhit () == KEYS_CODE ) // or var = getch (); if ( var == KEYS_CODE )
What is C++?
oh well just a counsl program. Possibly the esc key, if not ctrl+q, or something that "means" quit.
Alright then - use conio like Vicious showed you. It's not standrd, but it's common.
Yeah I know Rune is a big fan of it :P
Oh, and im ont sure if thats how it would work.. but probable.
Rune, I think you should look into SDL. Its not that hard really.
What is C++?
firstly I droped getch(). So I'm not a big fan on conio.h anymore.
And what is SDL?
Simple DirectMedia Layer. It's written more for C programmers but it will work in C++ also. It gives you graphics, sound, support for peripherals, threading, event handling, etc... Lots of good stuff. Go to www.libsdl.org to learn more.
kbhit() is used only to tell if a keystroke is waiting in the input buffer (according to my compiler's MSDN). It's used in combination with getch():
You can play around with it to suit your needs (although, as has been mentioned, it's very non-standard).Code:bool done = false; while(!done) { //do your game code or whatever if(kbhit()) { char theKey = getch(); if(theKey == 'X') done = true; } }
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Alright that bit of code I get a little more. It works fine too.if(kbhit())
{
char theKey = getch();
if(theKey == 'X')
done = true;
}
Thanks
Yeah thats what I meant :P
What is C++?