I'm fairly certain you can't do this through any shell, those are character stream based -- not event based.

As some people pointed out, Tk (or Gtk, or just about any Windowing system) can do this, becuase X (And it's alternate OS counterparts) are event driven.

This is from the Gtk-Perl Tutorial (I assume Tk is very similar)...

GTK is an event driven toolkit, which means it will sleep in main Gtk until an event occurs and control is passed to the appropriate function.

This passing of control is done using the idea of "signals". These signals are not the same as the Unix system signals, and are not implemented using them, although the terminology is almost identical. When something like the press of a mouse button occurs, the appropriate signal will be "emitted" by the widget that was pressed. This is how GTK does most of its useful work. There are signals that all widgets inherit, such as 'destroy', and there are signals that are widget specific, such as the 'toggled' signal on a toggle button.

...

In adddition to the signal mechanism described above, there is a set of events that reflect the X event mechanism. Callback may also be attached to these events. These events are:

...

  • key_press_event
  • key_release_event

In reply to Re: How can I get raw keydown and keyup events from a keyboard device? by hossman
in thread How can I get raw keydown and keyup events from a keyboard device? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.