Hi All,

I need a bit of help here. I'm trying get keyboard input (under UNIX and Windows) into a POE app which I'm developing. Having tried Curses and ReadLine, which work fine on UNIX, but won't install on Windows, I think I'll have to explore the POE-Tk route.

I've managed to get the code working without POE, but (being new to POE) I struggle to understand how to use the postback() and bind() functions.

...etc...
use Tk;
use POE qw( ... );

##UI Session##
POE::Session->create (
        inline_states => { _start => \&ui_start,
                           ev_key => \&ui_keypress },
                      );
$poe_kernel -> run();


##Start Event## sub ui_start {

        #Create main window - is heap storage necessary here??
        $_[HEAP]->{MainWindow} = $poe_main_window;
        #On keypress, call sub with a parameter -- **line 79**
        $poe_main_window->bind (
                '<Any-KeyPress>' => $_[SESSION]->postback( "ev_key" )
                                );

}

##Keypress Event##
sub ui_keypress {

        my($c) = $_[ARG0];              #Param should be a Tk Event
        my $event_obj = $c->XEvent;  #Get Event Object
        my $name = $event_obj->K;    #Get key name (e.g. comma)

print "The $name key was pressed\n";

}

Basically, I see this error:

Tk::Error: Can't call method "XEvent" on unblessed reference at **line 79.**Tk::After::once at D:/perl/site/lib/Tk/After.pm line 83
[once,[{},after#43,0,once,[\&POE::Kernel::_loop_event_callback]]]
("after" script)


I think my problem is that when the keypress event occurs, the "ev_key" happens, but I'm not so sure of how to extract the parameters that Tk would normally send along with this event.

I would very much appreciate any advice on this.
All the best,

James.




Reply via email to