Hi all!

I'm trying to detect Backspace input using Curses/Ncurses. So I have the 
following Perl script that isolates the problem I'm having:

{{{{{{{{{{
#!/usr/bin/perl

use strict;
use warnings;

use Curses;

my $main_win = Curses->new();
initscr();
noecho();
$main_win->keypad(1);

my $char = $main_win->getch();

my $ok = ($char eq KEY_BACKSPACE());

endwin();

print sprintf("%s\nGot %s\n", 
    ($ok ? "Got backspace" : "Did not get backspace"),
    $char
);

}}}}}}}}}}

On a konsole or xterm, after I press Backspace, I'm getting:

{{{
Did not get backspace
Got
}}}

On a Linux virtual console, it seems to work, and I'm getting "Got backspace".

Now, I implemented this program as a C program:

{{{{{{{{
/*
 * test-bs.c
 *
 * Compile with:
 *
 * gcc -Wall -o test-bs test-bs.c -lncurses
 *
 * */
#include <curses.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
    WINDOW * main_win;
    int ch;
    int ok;
    int expected;

    initscr();
    noecho();

    main_win = newwin(24, 80, 0, 0);
    
    keypad(main_win, 1);

    ch = wgetch(main_win);
    expected = KEY_BACKSPACE;

    ok = (ch == expected);

    endwin();

    printf(
        "%s\nGot: %i\nExpected: %i\n", 
        (ok ? "Got backspace" : "Did not get backspace"),
        ch,
        expected
    );

    return !ok;
}
}}}}}}}}

And on the xterm/konsole, I'm getting:

{{{
shlomi:$module$ ./test-bs
Did not get backspace
Got: 127
Expected: 263
}}}

Again - it works on a virtual console.

The funny thing is that I can recall it working correctly on konsole/xterm a 
few days ago, and then it stopped.

What should I do to get it working?

I'm using Mandriva Cooker on a Pentium 4 machine.

Regards,

        Shlomi Fish

-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
The Case for File Swapping - http://xrl.us/bjn7i

Shlomi, so what are you working on? Working on a new wiki about unit testing 
fortunes in freecell? -- Ran Eilam

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to