[Israel.pm] Curses Problem in Detecting Backspace

Shlomi Fish shlomif at iglu.org.il
Mon Sep 1 01:42:20 PDT 2008

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:


use strict;
use warnings;

use Curses;

my $main_win = Curses->new();

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

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


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


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

Did not get backspace

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;


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

    ch = wgetch(main_win);
    expected = KEY_BACKSPACE;

    ok = (ch == expected);


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

    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.


	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

More information about the Perl mailing list