Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Can I capture string typING in STDIN without press enter?

by daxim (Chaplain)
on May 29, 2012 at 16:36 UTC ( #973067=note: print w/replies, xml ) Need Help??

in reply to Can I capture string typING in STDIN without press enter?

Slightly modified synopsis of Term::TermKey::Async:
use strictures; use Term::TermKey::Async qw(FORMAT_VIM KEYMOD_CTRL); use IO::Async::Loop; use Time::HiRes qw(time); binmode STDOUT, ':encoding(UTF-8)'; my $loop = IO::Async::Loop->new; my $tka = Term::TermKey::Async->new( term => \*STDIN, on_key => sub { my ($self, $key) = @_; printf "Got key: %.8f %s\n", time, $self->format_key($key, FOR +MAT_VIM); $loop->loop_stop if $key->type_is_unicode and $key->utf8 eq "C +" and $key->modifiers & KEYMOD_CTRL; }, ); $loop->add($tka); $loop->loop_forever;
$ perl
Got key: 1338309112.93089604 我
Got key: 1338309112.93100500 喜
Got key: 1338309112.93102598 欢
Got key: 1338309115.18962908 吃
Got key: 1338309116.35776711 冰
Got key: 1338309116.35783195 淇
Got key: 1338309116.35785198 淋
Got key: 1338309116.78892303 。
You can see clearly from the timestamps how I grouped the words/phrases in the input method editor. Only once a phrase is complete in the IME, it is passed off to the terminal.

I haven't tested this on Windows.

Replies are listed 'Best First'.
Re^2: Can I capture string typING in STDIN without press enter?
by exilepanda (Pilgrim) on May 30, 2012 at 14:58 UTC
    Thanks but no luck... Term::TermKey is not available for Win32 =( Besides.. in win cmd prompt, there's no unicode, chars are formed in ANSI sequence. But thanks again.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973067]
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-02-18 06:01 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (250 votes). Check out past polls.