ok is the a way do do something like:
i know i use and if and i need to do something like the ketkey were if the user presses a key than the program will do some stuffCode:if(someone presses the up arrow) {than do this}
This is a discussion on get key? within the C++ Programming forums, part of the General Programming Boards category; ok is the a way do do something like: Code: if(someone presses the up arrow) {than do this} i know ...
ok is the a way do do something like:
i know i use and if and i need to do something like the ketkey were if the user presses a key than the program will do some stuffCode:if(someone presses the up arrow) {than do this}
I think you might want to look into Windows programming to do that, using the Windows procedure to peek for a message from the keyboard.
In just standard C++ for console apps, you can't do this...unless you're waiting for the user to press the ENTER key.
that helps alot
If your working with a Windows console this might be of some use. In combination with Virtual-Key Codes I think you could figure it out.
Regards,
BrianCode:#include <windows.h> #include <iostream> #include <cstdlib> using namespace std; WORD scanKeyboard(void) { DWORD dwCharsRead; INPUT_RECORD inRec; HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE); while(ReadConsoleInput(hInput, &inRec, 1, &dwCharsRead)) if(inRec.EventType == KEY_EVENT && inRec.Event.KeyEvent.bKeyDown) return(inRec.Event.KeyEvent.wVirtualKeyCode); return('ì'); // dummy return to suppress warning msg. } int main( int argc, char * argv[] ) { WORD c; do { cout << "\nEnter something, N to exit: "; c = scanKeyboard( ); cout << c; if(c == VK_UP) cout << " : Up Arrow key pressed"; }while(c !='N'); return(0); }