| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Accepts input character without pressing [ENTER]
hi all ,
i am new to this forum .. but i have a question and i cant find the answer anywhere on the internet .. i need to get an user input and accepts the input without the need of the user pressing enter ... below is my code ... i am running this code under solaris 9 if(nRetVal >= 0) { while(DbObj.getNextTrans()>=0) //getNextRec if getNextRec more than 0 (record exist) DbObj.printTransDetails(); //call function printTransDetails to output record char breakRec; cout << "Press [m] to Return to Main Menu" << endl; breakRec = getchar(); if(breakRec == 'm') //check if user input 'm' { return -1; } the problem with this code is that after the user enters m .. he needs to press enter or else the system wouldnt accept m as the input .. anyone ? please help ... thanks in advance |
|
#2
|
|||
|
|||
|
does it have to be "m" ?
why not just have it be "Press any key to return to the main menu" and use system("pause") ? or, use getchar() and have it be "Press [ENTER] to return to the main menu" Last edited by ubergeek : January 23rd, 2005 at 07:28 PM. Reason: added another solution |
|
#3
|
|||
|
|||
|
Hey! The problem is that getchar() requires the user to press enter. In windows, for example, there's a function like bioskey which allows you to detect the key code without enter. Try finding a function like that for solaris
|
|
#4
|
|||
|
|||
|
there's kbhit(), but that only tells you if a key has been pressed, not which one was pressed
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Accepts input character without pressing [ENTER] |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|