I don't think you can use the Win32::GUI::AcceleratorTable for a widget ( I couldn't get tit to work for the Textfield anyway ). But here is some code that does what you are looking for. At least I think it does. You should really post more code to show the situation you are dealing as well as tell us what you have tried so far. Anyway, here's some code that gives an example of at least one way to do it:
#!c:\perl\wperl.exe -w
use strict;
use warnings;
use Win32::GUI;
my $t_font = Win32::GUI::Font->new( -name => "Arial", -size => 7 );
my $accelerators = new Win32::GUI::AcceleratorTable("Return" => "Enter
+");
my $main = Win32::GUI::Window->new(-name=>'main',-text=>'test',-width=
+>200,-height=>200,-dialogui=>1,-accel=>$accelerators);
my $button1 = $main->AddButton(-name=>'button1',-top=>10,-left=>10,-te
+xt=>"button1",-ok=>0);
my $lotid = $main->AddTextfield(
-name => "lotid",
-keepselection => 1,
-top => 30,
-left => 10,
-width => 125,
-height => 20,
-font => $t_font,
-readonly => 0,
);
my $lotid_hwnd = $main->lotid->{-handle};
#print "Handle of the lotid textfield: $lotid_hwnd\n";
$main->Show();
Win32::GUI::Dialog();
exit;
sub Enter_Click
{
my $control_hwnd = $main->GetFocus();
#print "handle of the control with the focus: $control_hwnd\n";
if($control_hwnd == $lotid_hwnd)
{
$main->MessageBox("You pressed Return in while in the textfiel
+d. This is what was int he textfield: \"" . $lotid->Text() . "\"","En
+ter_Click");
button1_Click();
}
else
{
$main->MessageBox("You pressed Return in while NOT in the text
+field.","Enter_Click");
}
return 1;
}
sub button1_Click
{
$main->MessageBox("You clicked button1.","button1");
}
sub main_Termintate
{
$main->Hide();
return -1;
}
|