0

I know there is a way for the user to enter input and be able to accept it without the user having to press the Enter key but I do not know the command. Does anyone here know? For example, I have a menu like this:

A Add a record
D Delete a record
L Change last name
etc.

I want the user to type an 'A' and not have to hit the Enter key. The program just accepts the 'A' automatically. Thanks for any help. :p

4
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by Narue
0

That's not a portable operation, so we can't offer suggestions without at least knowing your operating system. Also knowing your compiler wouldn't hurt either.

0

I am running Windows XP. I also have a Borland compiler. Thanks. I did not know it was not a portable command.

0
// assuming u know that the key code of appropriate key...
// write these statments after the menu in your program
// KEYA, KEYB are the keycodes for key A, key B ...
// u can generate key code using getch();
if(kbhit())
          key=getch();
switch(key)
{ 
     case KEYA : // action when key A pressed...
     case KEYB : // action when key B pressed...
     .....
     default : //do nothing..
}

Edited by pyTony: fixed formating

0

You may use getch() or getche() function to archive this.
like:-
char ch;
ch=getch();
switch(ch)
{
case 'A':
function1(); // call funtion here
break;

case 'B':
function2(); // call funtion here
break;
}


Enjoy & Take Care!

0

Please check the time stamp of the last post before replying. This thread is over three years old. And use code tags when posting code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.