Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

How can I get raw keydown and keyup events from a keyboard device?

by Anonymous Monk
on Jan 19, 2002 at 23:45 UTC ( [id://140118]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

OK, I posted this as a reply to the recent question regarding unbuffered keyboard input, but I think it warrants its own question. I have an interest in getting waaaaay-raw keyboard input: keydown and keyup events. The jist is, I'd like to make a PC keyboard play as a MIDI instrument by binding keypresses and releases to midi events using the MIDI::Music module. I'm dreading doing something rash like resorting to Win32 API calls, is there some way I can get keydown and keyup messages in Perl on Linux? Is it in Term::Readkey and I'm just missing it in the docs? 'cause Term::Readkey's raw mode still looks like its interpreting it as a terminal ASCII stream and not the raw keyboard events that I really want to get at.
  • Comment on How can I get raw keydown and keyup events from a keyboard device?

Replies are listed 'Best First'.
Re: How can I get raw keydown and keyup events from a keyboard device?
by hossman (Prior) on Jan 20, 2002 at 02:33 UTC
    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
Re: How can I get raw keydown and keyup events from a keyboard device?
by clintp (Curate) on Jan 20, 2002 at 01:58 UTC
    Tk does this. You can independantly catch the key up and key down events.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://140118]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found