Agreeing (partially) with @leonerd, ncurses will only give you these keys, as they are used as modifiers for other keys (ignoring the ASCII escape character, which some people confuse with the Alt key). Some specific devices may be asked to provide this information (for example, the Linux console, as described in console_ioctl (4) ), but this is not a problem that ncurses will solve for you.
Refer to the ncurses FAQ. How can I use shift or control modifiers? for a long answer.
But short: ncurses does not tell you whether this modifier was used (except in special cases where there were widely known uses of shift ), but its descriptions in terms provide information either
- multiplying the actual function keys by a combination of shift and control modifiers or by
- using names based on the xterm function keys for the PC (shift 2, alt is 3, 5, etc.) to provide information.
There are two approaches: the first uses an array of no more than 60 function keys (good enough for shift and control combinations), and the other just uses custom names).
All of these modified keys give several bytes; an application using keypad()
(of course) in ncurses will get a single number. In the latter case, key codes are determined at runtime.
This applies mainly to special keys (function, edit, and cursor keys). For ordinary keys, we can assume that keyname
gives some special behavior, but when reading a description, this is not so:
- it reports ASCII control characters (which you can use with the
iscntrl
macro) and - makes assumptions about meta (which are only useful for
xterm
, the terminals that you most likely use) and - doesn't offer help for shift modifier.
From the terminals ... everyone has modifier information available internally, but the terminals usually do not have the ability to pass this information to applications. xterm
can do this using the modifyOtherKeys
resource,
modifyOtherKeys (class ModifyOtherKeys) Like modifyCursorKeys, tells xterm to construct an escape sequence for other keys (such as "2") when modified by Control-, Alt- or Meta-modifiers. This feature does not apply to function keys and well-defined keys such as ESC or the control keys. The default is "0": 0 disables this feature. 1 enables this feature for keys except for those with well- known behavior, eg, Tab, Backarrow and some special control character cases, eg, Control-Space to make a NUL. 2 enables this feature for keys including the exceptions listed.
which corresponds to the control sequence presented in the XTerm Control Sequences :
CSI > Ps; Ps m Set or reset resource-values used by xterm to decide whether to construct escape sequences holding information about the modifiers pressed with a given key. The first parameter iden- tifies the resource to set/reset. The second parameter is the value to assign to the resource. If the second parameter is omitted, the resource is reset to its initial value. Ps = 0 -> modifyKeyboard. Ps = 1 -> modifyCursorKeys. Ps = 2 -> modifyFunctionKeys. Ps = 4 -> modifyOtherKeys.
but (being an xterm-specific function), there is no reason to use it in ncurses: it would easily complicate getch
.