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;
Output:
$ perl termkey.pl
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 (Friar) 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.