views:

394

answers:

3

Hello All.

I am working on a simple console app to get my feet wet with curses again. I am having a bit of a problem porting my app from xp to AIX. Here is a sample chunk of code.

int main(void)
{
    WINDOW *_window = initscr(); 
    int _rows;
    int _cols;

    cbreak();

    /* Accept all keys */ 
    keypad(_window, true);

    /* Don't echo things that are typed */ 
    noecho();

    /* Get the screen dimensions */ 
    getmaxyx(_window, _rows, _cols);

    /* Don't display cursor */ 
    curs_set(0);

    for (;;)
    {
        printw("Press a Key ");
        refresh();
        int key = wgetch(_window);
        printw("%d \n", key);
    }

    endwin();

    return 0;
}

When I run this under XP, I get the following output from a DOWNARROW followed by a CTRL-DOWNARROW.

Press a Key 258
Press a Key 481
Press a Key

Suggesting 258 is the code for the down arrow, and 481 for ctrl-down arrow.

Performing this same test under AIX.

Press a Key 1858
Press a Key 27
Press a Key 79
Press a Key 66
Press a Key

The 1858 is the down arrow, and the 27/29/66 is the response for the ctrl-down arrow. I recognize that the 27/29/66 is probably one of the standard escape sequences. I was hoping that curses would map it to a single value. The XP side has a CTL_DOWN defined in the curses.h file. The AIX side does not.

So my question here is

Is them some incantation I missed here, that will magically map those three character into a nice unique integer? or do I have to write a class of some sort, to handle hiding the platform specific keystrokes into something my real app can use?

My eyes are blood shot from searching the AIX online stuff. Any help to point me in the correct direction would be appreciated.

Other random information

I am running xp pro, with the latest service packs msvc 6, with service pack 6. The curses library is pdcurses

The other compiler is IBM XL C/C++ ENTERPRISE EDITION V8.0 The compile uses

xlc++ -g app.cpp -lcurses

I am using pdcurses33 on the pc and the native curses on AIX.

A: 

I am amazed that no one has any ideas on this.

EvilTeach
Not really, I havnt used curses since the last centuary. And I dont think I've used recent app which uses curses.While I always liked apps which require nothing more than a vt100 emulation for thier interface, portability has always been a pain with curses apps.
James Anderson
+1  A: 

You could try using the open source "ncurses" libraries rather than the AIX supplied library which was heavily geared to IBM specific hardware and software libraries.

I cannot remember exactly if there is an xlC compatable version out there so you may have to build the library from source or switch to 'gcc'. Thier is also a version of ncurses for windows so you may be able to backport your changes to the original version of your code.

I have a vauge memory of ncurse supporting logical names like UP_ARROW etc. rather than numbers for the control keys. The problem depenfing on the platform, terminal emulation, NLS settings etc a simple up arrow could come back as 'UP_ARROW','Esc_UP', 'Cntrl_K'.

I do remember mapping several key strokes to one logical 'intention' like 'MEANT_UP' the last time I had to port a curses application to another platform (and that was a relativly easy AIX to Solaris port).

James Anderson
It's an idea at least.Thank you
EvilTeach
A: 

Re: [PDCurses] Alt + Shift + n (for example) on Windows

LM Fri, 12 Jul 2002 08:13:53 -0700

At 7/7/2002 6:10:00 PM, Jeremy Smith wrote:

I have run into a bit of a problem. I use the Curses function getch() in my program, for keys such as 'n' or Alt+'n' but how do I detect these combinations:

Ctrl+n Alt+Shift+n Ctrl+Alt+n Ctrl+Alt+Shift+n

I imagine there must be some kind of flag to return Shift+Alt+2 as an actual keycode (which is different from Shift, Alt or 2), but I don't know how. :-(

I checked the header for file for curses.h and they appear to list all the standard scan codes you can get back from a keyboard, including some ALT combinations and a few of the Control combinations.

Then I checked the Windows implementation for getting a character. In pdckbd.c the routine win32_kbhit calls ReadConsoleInput. The shift, alt, control and other status keys are returned from this function in the dwControlKeyState. The PDC_get_bios_key reports what key is pressed using the two kptab tables (kptab and ext_kptab), so if the combination is not in the table, you probably aren't seeing it. You may be able to add some definitions to the tables if something is missing. There's also some code in the same routine that sets the states (BUTTON_SHIFT, BUTTON_CONTROL, BUTTON_ALT), but this appears to be for mouse input. So you can check these keys in the MOUSE_STATUS structure. This only pertains to the Windows implementation. Every platform has a unique way of figuring out which keys are pressed.

In 16 bit DOS, I used to change the state of shift, caps lock and num lock by changing the settings at the hex 417 address. This only works for real mode programs. Many of the new Windows compilers don't even allow you to access bios or memory directly with functions any more. The 16 bit location at hex 417 and hex 418 indicates that the right shift has been pressed by setting the highest bit at the 417 address, the left shift, by setting the second highest bit in the byte, the ctrl key by setting the next highest and the alt key by the next highest after that. The 418 address holds the status of whether or not the right or left alt and control keys were pressed.

It appears as though you may have to make some modifications to your particular version of curses to get exactly what you want. Curses is a very portable user interface, thus it often supports the lowest common denominator of features on some platforms.

By the way, I remember reading that there was work underway for a new curses standard that included international character support. Has anyone heard anything further on this effort?

Best wishes.

Laura Michaels http://www.distasis.com

It looks like i need to do my own keyboard decoding.

EvilTeach