954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accepting user input

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

tat2dlady
Light Poster
32 posts since Jan 2005
Reputation Points: 10
Solved Threads: 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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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

tat2dlady
Light Poster
32 posts since Jan 2005
Reputation Points: 10
Solved Threads: 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..
}

kunal_ktr
Newbie Poster
10 posts since Oct 2004
Reputation Points: 10
Solved Threads: 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!

jantazone
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You