Re: Does the Glib mainloop have the ability to capture keypresses?




On Feb 14, 2007, at 5:50 PM, zentara wrote:

I have plenty of examples for Gtk2 windows, and capturing
keyboard events, but I hav'nt found anything for Glib alone,
for use in commandline loops.

That's because the keypresses that gtk+ deals with are simply X events, not characters on a serial terminal stream.


I can put
Glib::IO->add_watch (fileno 'STDIN', [qw/in/], \&watch_callback);

and watch what is input on STDIN, but is that the best way?

I took that approach in gish, where i faked out the Tk portion of Readline.

http://asofyet.org/muppet/software/gtk2-perl/gish.html


But it is important that you set up STDIN properly to give you all the characters pressed, instead of using line-buffering. Readline does that for you... in your own app, you'll have to use the termios stuff from the POSIX module.


--
If the monkey could type one keystroke every nanosecond, the expected waiting time until the monkey types out Hamlet is so long that the estimated age of the universe is insignificant by comparison ... this is not a practical method for writing plays.
  -- Gian-Carlo Rota





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]