#!/usr/bin/perl use warnings; use strict; use Glib; use Term::ReadKey; use threads; $|++; ReadMode('cbreak'); # works non-blocking if read stdin is in a thread my $count = 0; my $thr = threads->new(\&read_in)->detach; my $main_loop = Glib::MainLoop->new; my $timer = Glib::Timeout->add (1000, \&timer_callback, undef, 1 ); # can also have filehandle watches #my $watcher; #$watcher = Glib::IO->add_watch( fileno( $pty ), ['in', 'hup'], \&callback); # must be done after main_loop is running #Glib::Idle->add( sub{}); #print "$ps\n"; my $timer1 = Glib::Timeout->add (10, \&testcallback, undef, 1 ); $main_loop->run; ReadMode('normal'); # restore normal tty settings sub testcallback{ my $ps = `ps auxww`; print "$ps\n"; return 0; #only run once } sub timer_callback{ #do stuff $count++; print "\n$count\n"; return 1; } sub read_in{ while(1){ my $char; if (defined ($char = ReadKey(0)) ) { print "\t\t$char->", ord($char),"\n"; #process key presses here if($char eq 'q'){exit} #if(length $char){exit} # panic button on any key :-) if($char eq 'p'){ Glib::Idle->add( sub{ my $ps = `ps auxww`; print "$ps\n"; return 0; # run only once } ); } } } } __END__