私のGUIが単一のキーストロークで反応するようにしたい。Win32 :: GUI :: AcceleratorTableの構文
これは、ウィンドウオブジェクトにフォーカスがある限り、-keydownオプションを指定すると問題なく動作します。
フォーカスのないキーストロークに関するフィードバックを得るには、Win32 :: GUI :: AcceleratorTableを使用します。
ドキュメントでは、私のコードで見ることができるコードスニペットを取った。しかし、私は使用する構文について混乱しています。 DocsがWin32 :: GUI :: Acceleratorと言い、他にWin32 :: AcceleratorTable(CPANにそのようなパッケージがないにもかかわらず)が記述されています。 -accel、-accelerators、-acceleratortableのオプションと同じです。
キーストロークのキーコードに関するフィードバックを得るには、どのようにコードを表示する必要がありますか?ここで
は私の(動作しない)コードです:
use strict;
use warnings;
use Win32::GUI();
# define main window
my $window = Win32::GUI::Window->new(
-name => 'MainWindow',
-width => 250,
-height => 200,
-text => 'keys',
-accel => Win32::GUI::AcceleratorTable, # ????
# or -accelerator, or -acceleratortable # ????
);
$window->AddLabel(-name => 'lblStatus', -top => 5, -left => 5, -text => "pressed key",);
# a text field to give feedback about the key press
$window->AddTextfield(-name => 'txtStatus',
-width => 80,
-height => 20,
-top => 20,
-left => 5,
-tip => "displays value of key",
);
# I took this from CPAN Win32::GUI::AcceleratorTable which should at least print
# "Hello" on the console if one presses the lowercase letter "b" on the keyboard
$A = Win32::GUI::AcceleratorTable->new(
"Ctrl-X" => "Close",
"Shift-N" => "New",
"Ctrl-Alt-Del" => "Reboot",
"b" => sub { print "Hello\n"; },
);
# display app
$window->Show();
# start of event handler
Win32::GUI::Dialog();
exit (0);
:-)作品もあなたがの初期化を移動する必要があります意味 '-accel => $ A'、する必要があります'$ A'です。 ( '-accel'、' -accelerator'と '-accelerratortable'はエイリアスです。) – ikegami