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


Reply via email to