View Full Version : Getting XON/XOFF Characters with getchar()
psyba
2005.04.10, 08:24 PM
I would think that this would be fairly basic, but I can't seem to get the XON (Ctrl-q) and XOFF (Ctrl-s) characters from the keyboard with getchar() where I can get the other control characters (with the exception of the ones that generate signals which are captured in a signal handler). This has to compile on linux as well. I'm using curses if that helps in anyway. I noticed curses changes '\n' to '\r' with getchar() so I am wondering if this is a curses problem or something I am just not doing right. I tried it over ssh on a linux box and got the same results. So I thought it may be the terminal but emacs works over ssh so I am not getting what I am doing wrong (or not doing if this is a special case).
"\n" is the newline character, which is locale dependent, while "\r" is the just the carriage return code, which is typically what you get when you press the (carriage) return key. The application is responsible for converting that to the correct newline char if you insist on using getchar. Also, I assume ctrl-q and ctrl-s are captured by the OS or terminal and then something mysterious happens ;)
psyba
2005.04.11, 10:17 AM
I found a solution that works on Linux, cannot confirm until later on Mac OS X
#include <stdio.h>
#include <termios.h>
main () {
struct termios ttystate;
tcgetattr( 0, &ttystate); /* read curr. setting */
ttystate.c_lflag &= ~ICANON; /* no buffering */
ttystate.c_lflag &= ~ECHO; /* no echo */
ttystate.c_iflag &= ~IXON ; /* XON/XOFF Enabled */
tcsetattr( 0 , TCSANOW, &ttystate); /* install settings */
while(1)
printf("%d", getchar());
}
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.