LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-04-2007, 06:22 AM   #16
culin
Member
 
Registered: Sep 2006
Distribution: Fedora Core 10
Posts: 254

Original Poster
Rep: Reputation: 32

oh... but will any of the funcitons tcgetattr() tcsetattr() can echo a charecter on the screen by taking the input from the standard input device (keyboard)?? and what makes those functions getch() nocbreak() echo() worse ???
thanks....
 
Old 01-04-2007, 08:37 AM   #17
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 111Reputation: 111
He's saying don't use curses if you don't really need curses (with a little subtle warning about the kind of headaches you get with curses, I can't vouch for that part). Instead, put the terminal into raw mode like
Code:
   struct termios cur,raw;
   tcgetattr(STDIN_FILENO,&cur);
   raw=cur;
   raw.c_lflag&=~(ICANON|ECHO|ISIG);
   raw.c_cc[VMIN]=1;
   raw.c_cc[VTIME]=0;
   tcsetattr(STDIN_FILENO,TCSAFLUSH,&raw);
and restore by doing
Code:
   tcsetattr(STDIN_FILENO,TCSAFLUSH,&cur);
See the respective man pages to figure out how it works.

Last edited by tuxdev; 01-04-2007 at 08:48 AM.
 
Old 01-04-2007, 10:13 AM   #18
Siiiiiii
LQ Newbie
 
Registered: May 2006
Location: Sweden
Distribution: Vector Linux
Posts: 28

Rep: Reputation: 15
What's wrong with using curses?
 
Old 01-04-2007, 10:22 PM   #19
culin
Member
 
Registered: Sep 2006
Distribution: Fedora Core 10
Posts: 254

Original Poster
Rep: Reputation: 32
thanks tuxdev.....
but my question is as we do in VC++ to echo a charecter...........say char ch; ch=getch(); this will echo the charecter typed by the user and quits....so,can same thing work in linux...???? if no what to do to echo a charecter on the screen here ?? and the prototypes as in man pages for getch() cbreak() raw() and echo() simply accept nothing and returns int... how to use those in the programs...is there something else to be done...please gimme a simple code to echo a charecter on the screen...
 
Old 04-07-2007, 11:02 PM   #20
Kumado
Member
 
Registered: Oct 2003
Location: Ohio , USA
Distribution: up to Suse 10.2
Posts: 63

Rep: Reputation: 19
getch in linux

I am working at programming in Linux as well. I am used to the getch() command in windows and the getche() [which does the echo] that gets one character from the keyboard and continues right on.

What you rarely get is a real answer. It is a waste of time getting replies like that.

This site:

http://members.cox.net/midian/articles/ansic9.htm

is the 1st I have been able to find that comes close at all.
It uses getchar() command BUT you must hit return to continue.

Also :

http://www.linuxjournal.com/article/1138

lists the info on "one-character-at-a-time mode (getch() in DOS)". It seems good to have the device active like this and not waiting for the user forever but who would know to look for this?

I am looking to write a simple texted based game and I really do not want to press enter after every key.

I am looking further myself but if you find or have found anything, please let me know.

kumado

Last edited by Kumado; 04-07-2007 at 11:15 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is getch()....... rajsun Programming 2 03-28-2005 11:40 AM
getch function prasad514 Programming 6 01-03-2005 11:48 AM
Help with getch... darkarcon2015 Programming 4 09-12-2004 08:48 AM
how to get getch() working with c++ cool_ashwin22 Programming 3 08-03-2004 10:58 AM
ncurses getch() deveraux83 Programming 3 08-06-2003 07:27 AM


All times are GMT -5. The time now is 11:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration