Re: ## Capturing ctrl key in linux ##
From: Kevin L (kevinl01_at_earthlink.net)
Date: 05/30/04
- Previous message: Otto Wyss: "Tutorial and guidelines: A proposal for better OpenSource code (long message)"
- In reply to: M.Senthil Kumar: "## Capturing ctrl key in linux ##"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 May 2004 18:57:59 GMT
M.Senthil Kumar wrote:
> hai all,
> I'm developing an editor software in linux kernal 2.4 using C.I
> don't know how to capture Control Key . I want to capture ^F ,
> ^E,^C,^H for my editor to show menus.I'm using curses laibrary for my
> software.
> Will u please help me how to do that.
>
>
> Senthil kumar. M
What you need is to call raw() after initscr(). You may also need to call
nonl() to handle carriage-return correctly. Your control characters will come
in as (char)0x00 (CTRL-space or CTRL-@) through (char)0x1F (CTRL-underscore or
CTRL-?). The iscntrl() function will correctly identify these -- but note that
0x80 through 0x9F are ALSO control characters on the 8-bit Linux console.
My project's startup sequence looks similar to this:
initscr();
raw();
noecho();
nonl();
intrflush(stdscr, FALSE);
meta(stdscr, TRUE);
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
My keyboard handler loop relies on wgetch(stdscr). I check for three special cases:
ERR - no key available, return
KEY_RESIZE - call getmaxyx(), refresh screen
0x1B - ESCAPE key, which I turn into an "ALT" flag. Then I call wgetch() again
for the actual keystroke I'm claiming was pressed in addition to ALT/META. So
the two-keystroke combination ESCAPE + 'g' is mapped to "ALT-g" before I begin
processing it.
Finally, if you're *outputting* directly to the Linux console on i386-based
systems (*not* a X11-based emulator) and you want PC-VGA glyphs ("CP437") in the
control character range, you can printf("\033(U\033[3h") before initscr() and
printf("\033(B\033[3l") after endwin(). This will set your G0 character set to
PC-VGA and enable DECCRM (display control chars) and restore the default setting
upon exit. Not all control chars will be visible though: 0x00, 0x07, 0x08,
0x09, 0x18, 0x1A, 0x1B, and 0x9B do not render on my own development box. (This
may be more trouble than it's worth though -- if you want to support X11-based
emulators you'll have to dynamically map the CP437 chars to ACS_* characters
before calling addch(), and most of them do not have equivalent ACS_* glyphs.)
- Previous message: Otto Wyss: "Tutorial and guidelines: A proposal for better OpenSource code (long message)"
- In reply to: M.Senthil Kumar: "## Capturing ctrl key in linux ##"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|