Trapping the Tab Key.......

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 14
Reputation: ajaxjinx is an unknown quantity at this point 
Solved Threads: 0
ajaxjinx ajaxjinx is offline Offline
Newbie Poster

Trapping the Tab Key.......

 
0
  #1
Apr 3rd, 2007
Hi,


I am making a small software. As a part of the Command Line Interface I am supposed to include the "tab help facility" .Incase the user is typing a command and in between he presses the Tab key, the software should display all the avavilable commands.


I am unable to trap the Tab ...

And ofcourse the Coding is in C..
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Trapping the Tab Key.......

 
0
  #2
Apr 3rd, 2007
As you need to trap a single key, I don't think you can use getline/s().
Just catch every character typed using getchar/ch() and echo it back using putxx() if it's not the tab char.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Trapping the Tab Key.......

 
0
  #3
Apr 3rd, 2007
Well a lot depends on your OS and compiler.
Are you allowed to use libraries like ncurses?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Trapping the Tab Key.......

 
0
  #4
Apr 3rd, 2007
if you are using c++ we can write portable code
  1. std::cin >> std::noskipws ;
  2. char ch ;
  3. std::cin >> ch ;
  4. if( ch == '\t' ) /* ... */ ;// tab
  5. else /* ... */ ; // something else
Last edited by ~s.o.s~; Apr 3rd, 2007 at 1:46 pm. Reason: Fixed code tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 14
Reputation: ajaxjinx is an unknown quantity at this point 
Solved Threads: 0
ajaxjinx ajaxjinx is offline Offline
Newbie Poster

Re: Trapping the Tab Key.......

 
0
  #5
Apr 4th, 2007
1.I am working on LINUX
2. Using C, not C++
3I can Download extra lib if the need be.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Trapping the Tab Key.......

 
0
  #6
Apr 4th, 2007
Originally Posted by ajaxjinx View Post
1.I am working on LINUX
2. Using C, not C++
3I can Download extra lib if the need be.
Depends on if you want the user to press the return/enter key first. If not, you'll probably want to code with something like [search]NCurses[/search].
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Trapping the Tab Key.......

 
0
  #7
Apr 4th, 2007
Originally Posted by joeprogrammer View Post
Depends on if you want the user to press the return/enter key first. If not, you'll probably want to code with something like [search]NCurses[/search].
I think the user doesn't press the return key.
"Incase the user is typing a command and in between he presses the Tab key, the software should display all the avavilable commands."
Kinda like word completion in shells.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 14
Reputation: ajaxjinx is an unknown quantity at this point 
Solved Threads: 0
ajaxjinx ajaxjinx is offline Offline
Newbie Poster

Re: Trapping the Tab Key.......

 
0
  #8
Apr 4th, 2007
Yes, I dont want the user to have to press the return key.

Can any one please explain in detail, how the Ncurses thing works...
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 14
Reputation: ajaxjinx is an unknown quantity at this point 
Solved Threads: 0
ajaxjinx ajaxjinx is offline Offline
Newbie Poster

Re: Trapping the Tab Key.......

 
0
  #9
Apr 4th, 2007
@ kashyap.. Man I dont want the user to press the ReTURN key. I mean, the 1st method that u suggested would not work in this situation...

???
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Trapping the Tab Key.......

 
0
  #10
Apr 4th, 2007
ncurses (or curses) is installed by default by
most linux distros. try man curses to check.

install ncurses-development package if
it is not already installed.

while writing code,
#include <ncurses.h> // or <curses.h>
int main()
{
    initscr() ; // must be called first
    cbreak() // disable the buffering
     // required to get a character immediately
     // without waiting for return key.
 
    noecho();   // only if u want to suppress 
      // echo of input keys
  
     keypad(stdscr, TRUE);   // only if u want
     // to read special keys (delete,arrow keys etc.)

     // to read a character, use
     int getch(void) ; 
    // normally getch waits till a 
    // key is hit. to work in a 
    // nonblocking manner, call
   // nodelay(stdscr,   TRUE) ;
   // in this case getch will return 
   // ERR if key input is   not available.
 
    endwin() // must be called before exiting
    // to restore the terminal settings.
   
   return 0 ;
}

compiling/linking:
either gcc. -lncurses your_program.c
or gcc your_program.c libncurses.a

link statically to the ncurses library
if u want to run your program on machines
where ncurses is not installed.



Last edited by vijayan121; Apr 4th, 2007 at 12:37 pm. Reason: formatting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC