#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = 'Tk::MainWindow'->new; my $current = 0; my @buttons = map { my $i = $_; $mw->Button(-text => $i, -command => sub { $current = $i } )->pack } 1, 2; $mw->after(100, sub { $mw->eventGenerate('', -keysym => $_) for qw( Tab Return ); $mw->idletasks(); $mw->DESTROY; }); Tk::MainLoop(); use Test::More tests => 1; is $current, 1, 'Events processed'; #### $ tktest.pl 1..1 ok 1 - Events processed $ Xvfb :19 & $ pid=$! $ DISPLAY=:19 tktest.pl 1..1 not ok 1 - Events processed # Failed test 'Events processed' # at /home/choroba/tktest.pl line 27. # got: '0' # expected: '1' # Looks like you failed 1 test of 1. $ kill $pid