Re: ## Capturing ctrl key in linux ##

From: Kevin L (kevinl01_at_earthlink.net)
Date: 05/30/04

  • Next message: Nick Landsberg: "Re: Tutorial and guidelines: A proposal for better OpenSource code (long message)"
    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.)


  • Next message: Nick Landsberg: "Re: Tutorial and guidelines: A proposal for better OpenSource code (long message)"

    Relevant Pages

    • Re: Passwords on Linux systems(for all flavors)
      ... >>constraints for the various linux flavors. ... >>like number of key spaces or the key length, ... nor any restriction on which characters the ... if a password contains any control characters or non-ASCII ...
      (Focus-Linux)
    • Proftp banner
      ... Iam using proftp on our linux machine. ... How can I remove the banner or replace it with some ... Kumar ... Padiyath Sreekumar | Tel: +41.56.310.3643 ...
      (RedHat)
    • tdom installation
      ... I need tDOM package which can support tcl 8.4, t o install in a linux ... Anil A Kumar ...
      (comp.lang.tcl)