|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Reading an input without the hitting <ENTER> key
Hi, can anyone tell me hopw can i read an input from a unix script with out the user hitting the enter key. Is this possible???
Appreciate your help.. |
|
#2
|
|||
|
|||
|
You have to have a utility written in C to do it.
read and other input facilities depend on the user hitting return key. This is the standard way to read single characters - this is a c function, you could put it into a simple C program and use it. Code:
#include <termios.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
/*------------------------------------------------*/
int getch(void) {
int c=0;
struct termios org_opts, new_opts;
int res=0;
//----- store old settings -----------
res=tcgetattr(STDIN_FILENO, &org_opts);
assert(res==0);
//---- set new terminal parms --------
memcpy(&new_opts, &org_opts, sizeof(new_opts));
new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
c=getchar();
//------ restore old settings ---------
res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
assert(res==0);
return(c);
}
|
|
#3
|
|||
|
|||
|
Hey Jim, what about that magical bash script command "getkey" that marugesanfavors
what was that about? -Steven __________________ Run away from the hills! If you see the hills, run the other way! –Edmund Black Adder |
|
#4
|
|||
|
|||
|
He wrote back that it was a C utility - probably like what I posted.
|
|
#5
|
|||
|
|||
|
I figured as much... I'm sure it confused thread-poster throroughly...
-Steven |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Reading an input without the hitting <ENTER> key |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|