Is this a good place to ask questions about curses.h.
I'm getting the following error when trying to complie my program
undefined reference to 'keypad'
undefined reference to 'timeout'
I am using -lcurses in my makefile.
I need a way to determine if a key has been pressed. Once a key is
pressed, I need to get the keystroke without waiting for the return
key to be pressed.
I'm a Windows guy and normally I would use the kbhit()/getchar
combination. How would I do it in LynxOS
John
check out termio.h and ICANON
I will check it out but I have no idea what I'm looking for. I do
Windows not lynx and I'm not sure what I'm suppose to be checking out.
I'm getting closer. Now I have the explaination of all the fields and
stuff. But I still don't know how to use it.
Do I use ioctl() to set the c_lflag. If true, what is the syntax? How
do I open the standard terminal or console?
Got any sample code?
Remember, I'm a newbie to Unix stuff.
Sorry for my ignorance.
something like
struct termio currentSettings;
int fd;
int c;
if( (fd = open( device, O_RDWR )) < 0 )
{
perror( "Error: failed to open device %s\n", device );
exit( -1 );
}
if( ioctl(fd, TCGETA, (char *)¤tSettings) < 0 )
{
perror( "Failed to get current settings" );
return -1;
}
but I have extracted the code from varius sources - so beware of
errors and ommissions :)
/* disable XON/XOFF control */
currentSettings.c_iflag &= ~( IXON | IXOFF );
/* set baud rate and line format */
currentSettings.c_cflag &= ~V_CBAUD;
currentSettings.c_cflag |= baudRate;
currentSettings.c_cflag &= ~V_CSIZE;
currentSettings.c_cflag |= wordSize;
currentSettings.c_cflag |= CREAD;
currentSettings.c_cflag &= ~V_PARODD;
if( parity )
currentSettings.c_cflag |= V_PARENB;
else
currentSettings.c_cflag &= ~V_PARENB;
/* set raw input / output mode - characters are passed straight to the
application */
currentSettings.c_lflag &= ~V_ICANON;
currentSettings.c_lflag &= ~V_ISIG;
currentSettings.c_lflag &= ~V_ECHO;
/* set 500mSec delay on inputs */
currentSettings.c_cc[VMIN] = 0;
currentSettings.c_cc[VTIME] = 10;
/* Set up input stream translations */
currentSettings.c_iflag &= ~V_ICRNL;
if( ioctl(fd, TCSETA, (char *)¤tSettings) < 0 )
{
perror( "Failed to write port settings" );
return -1;
}
for( ;; )
if( read( fd, &c, 1 ) )
{
// do something
}
else
usleep( 10000 );
i have just noticed that you said console or terminal
Assuming that your application is running on the console, you already
have it open (STDIN) and the following code may be more useful to work
from
#include <unistd.h>
#include <sys/ioctl.h>
#include <termio.h>
#include <stdio.h>
static struct termio originalIoSettings; // buffer for original
buffer settings
static struct sgttyb originalTtySettings;
/*
+**************************************************************************
* Description : Set terminal to non-canonical mode, i.e. char-by-char
* Returns :
*-
**************************************************************************/
int inhibitStdinInBuffering( void )
{
struct termio newIoSettings, *t = &newIoSettings;
ioctl( STDIN, TCGETA, (char *)&originalIoSettings );
ioctl( STDIN, TCGETA, (char *)t );
t->c_lflag &= ~(V_ICANON | V_ISIG);
t->c_cflag &= ~V_CBAUD;
t->c_cflag |= V_B9600;
t->c_cc[VMIN] = 0;
t->c_cc[VTIME] = 0;
return( ioctl( STDIN, TCSETA, (char *)t) );
}
/*
+**************************************************************************
* Description : Restore terminal to initial state prior to using
* inhibitStdinInBuffering()
* Returns : nothing
*-
**************************************************************************/
void resetStdInMode( void )
{
ioctl( STDIN, TCSETA, (char *)&originalIoSettings );
}
/*
+**************************************************************************
* Description : Sets tty input to raw processing mode
* Returns : nothing
*-
**************************************************************************/
int inhibitTtyBuffering( void )
{
struct sgttyb newTtySettings;
ioctl( STDIN, TIOCGETP, (char *)&originalTtySettings );
ioctl( STDIN, TIOCGETP, (char *)&newTtySettings );
newTtySettings.sg_flags |= CBREAK;
return( ioctl( STDIN, TIOCSETP, (char *)&newTtySettings ) );
}
/*
+**************************************************************************
* Description : Sets tty port to original processing mode
* Returns : nothing
*-
**************************************************************************/
void resetTtyMode( void )
{
ioctl( STDIN, TIOCSETP, (char *)&originalTtySettings );
}
/*
+**************************************************************************
* Description : Best attempt at standard function for getch() -
non pause character
* i/o
* inhibitStdinInBuffering() must be called prior to getch()
* and resetStdInMode() called afterwards prior to program exit
* Returns : character or -1=non available
*-
**************************************************************************/
int getch( void )
{
char cBuffer;
return read( STDIN, &cBuffer, 1 ) == 1 ? cBuffer : -1;
}
thanks. I'll give it a try the first chance I get. I'm putting out
another fire right now.