KovaaK has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use IO::Socket; use Term::ReadKey; ReadMode 1; my ($PORT, $server, $client); $PORT = 9000; # pick something not in use $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1 ); die "can't setup server" unless $server; print "[Server accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); print "Received connection!\n"; while (1) { my ($key); while (not defined ($key)) { $key = ReadKey(-1); } print "Get key $key\n"; print $client "$key\n"; $key = ReadKey(-1); #clear $key } } close $client; ReadMode 0;
#!/usr/bin/perl -w use strict; use IO::Socket; use Win32::GuiTest qw(:ALL); my $host = shift || 'localhost'; my $port = shift || '9000'; my ($kidpid, $socket, $line); # create a tcp connection to the specified host and port $socket = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port ) or die "can't connect to port $port on $host: $!"; print "[Connected to $host:$port]\n"; while (1) { while (defined ($line = <$socket>)) { sleep(1); chomp($line); SendKeys($line); print "$line\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading keyboard input without focus
by Mr. Muskrat (Canon) on Nov 24, 2008 at 20:42 UTC | |
by KovaaK (Initiate) on Nov 24, 2008 at 22:02 UTC | |
|
Re: Reading keyboard input without focus
by lostjimmy (Chaplain) on Nov 24, 2008 at 21:23 UTC | |
by KovaaK (Initiate) on Nov 24, 2008 at 22:14 UTC | |
by lostjimmy (Chaplain) on Nov 24, 2008 at 23:02 UTC | |
|
Re: Reading keyboard input without focus
by Mr. Muskrat (Canon) on Nov 24, 2008 at 20:31 UTC | |
by KovaaK (Initiate) on Nov 24, 2008 at 20:38 UTC | |
|
Re: Reading keyboard input without focus
by KovaaK (Initiate) on Nov 24, 2008 at 20:22 UTC |