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.
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 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.