Unix Programming - ncurses backspace

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2005 > ncurses backspace





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ncurses backspace
leonard

2005-08-25, 2:54 am

Hi

I can't get my program to read the backspace key.
here is my code;

initscr();
noecho();
cbreak();
keypad(stdscr, TRUE);

while ((ch = getch()) != KEY_F(1)) {
switch (ch) {
case KEY_BACKSPACE;
delch(ch);
continue;
case KEY_UP;
...
case KEY_DOWN;
...

And when I run the program I get ^? when I press
the backspace key. All the other keys work.


Fletcher Glenn

2005-08-25, 6:04 pm


"leonard" <lg@cgl-os.org> wrote in message
news:pan.2005.08.25.07.00.20.366328@cgl-os.org...
> Hi
>
> I can't get my program to read the backspace key.
> here is my code;
>
> initscr();
> noecho();
> cbreak();
> keypad(stdscr, TRUE);
>
> while ((ch = getch()) != KEY_F(1)) {
> switch (ch) {
> case KEY_BACKSPACE;
> delch(ch);
> continue;
> case KEY_UP;
> ...
> case KEY_DOWN;
> ...
>
> And when I run the program I get ^? when I press
> the backspace key. All the other keys work.
>
>


The ^? means that your keyboard has output the delete character.
The backspace character is ^H. So, you need to add an addtional
case to your character switch for the delete character.

By the way. case statements end with a ":" not a ";".

--

Fletcher Glenn


leonard

2005-08-25, 6:04 pm

On Thu, 25 Aug 2005 16:53:49 +0000, Fletcher Glenn wrote:

>
> "leonard" <lg@cgl-os.org> wrote in message
> news:pan.2005.08.25.07.00.20.366328@cgl-os.org...
>
> The ^? means that your keyboard has output the delete character.
> The backspace character is ^H. So, you need to add an addtional
> case to your character switch for the delete character.
>
> By the way. case statements end with a ":" not a ";".


Yes I know, my shift key does not work
Thanks for the info.
Thomas Dickey

2005-08-25, 6:04 pm

leonard <lg@cgl-os.org> wrote:

> And when I run the program I get ^? when I press
> the backspace key. All the other keys work.


ncurses returns KEY_BACKSPACE if the key happens to match the terminfo
string for kbs. See the result from infocmp to see what ncurses is looking
for.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Brian Raiter

2005-08-25, 6:04 pm

> I can't get my program to read the backspace key.
> here is my code;


[...]

> And when I run the program I get ^? when I press
> the backspace key. All the other keys work.


For many terminals, ^? is the code that indicates the backspace
key. For others, it is ^H.

It sounds like your terminal is sending ^? but your terminal
configuration is telling ncurses that your terminal will send ^H.
It's possible that your TERM variable is set incorrectly, or perhaps
you've unknowingly used stty(1) to change your terminal configuration.

Because both of these codes (^? and ^H) are so commonly associated
with the backspace key in the Unix, a lot of terminal software is
hacked to accept either key as backspace, regardless of the actual
configuration. The result of this fact is that people will have their
backspace key misconfigured and won't know it until they test some
software that they've written themselves.

b

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com