Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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;
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.


Comment on Re: Can I capture string typING in STDIN without press enter?
Download Code
Re^2: Can I capture string typING in STDIN without press enter?
by exilepanda (Monk) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-17 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls