Perlで無理ゲーム攻略 (How to play Win32::GuiTest)
http://yapcasia.org/2011/talk/32
某MMORPGでゲーム中にPerlの同時起動を遮断する機能が追加されたことがありました。
Win32::GuiTest や Win32::Screenshot などのモジュールを利用して、Windows上で
動作するゲームを自動でプレイするPerlプログラムを作成する方法について解説します。
Once upon a time, perl.exe was banned during a game by MMORPG.
I will explain how to create the Perl bot program which plays
automatically games on Windows using some modules such as
Win32::GuiTest and Win32::Screenshot.
19. SendKeys($keys)
Name Action Name Action
{BACKSPACE} Backspace {PRTSCR} Print screen
{BS} Backspace {RIGHT} Right arrow
{BKSP} Backspace {SCROLL} Scroll lock
{BREAK} Break {TAB} Tab
{CAPS} Caps Lock {UP} Up arrow
{DELETE} Delete {PAUSE} Pause
{DOWN} Down arrow {F1} Function Key 1
{END} End ... ...
{ENTER} Enter {F24} Function Key 24
{ESCAPE} Escape {SPC} Spacebar
{HELP} Help key {SPACE} Spacebar
{HOME} Home {SPACEBAR} Spacebar
{INSERT} Insert {LWI} Left Windows Key
{LEFT} Left arrow {RWI} Right Windows Key
{NUMLOCK} Num lock {APP} Open Context Menu
{PGDN} Page down Key
{PGUP} Page up
20. (2) FindWindowLike, GetWindowRect
GetWindowText, GetClassName
use Win32::GuiTest qw(:ALL);
system("start calc.exe");
sleep(1);
my @id = FindWindowLike(undef,"^電卓","",undef,1);
my $id = $id[0];
print GetWindowText($id), "¥n";
print GetClassName ($id), "¥n";
my ($x1, $y1, $x2, $y2) = GetWindowRect($id);
print "($x1, $y1)->($x2, $y2)", "¥n";
21. (3) Win32::Screenshot
CaputureRect #=> Image::Magick object
use Win32::Screenshot qw(CaptureRect);
my $img = CaptureRect(20, 10, 800, 500);
print $img; # Image::Magick=ARRAY(0xbeef)
$img->Write("x.png"); # save
system("start x.png"); # view
22. (4) Win32::GuiTest & Win32::Screenshot
Capture only “calc.exe” window
use Win32::GuiTest qw(:ALL);
use Win32::Screenshot qw(CaptureRect);
system("start calc.exe");
sleep(1);
my @id = FindWindowLike(undef,"^電卓","",undef,1);
my ($x1, $y1, $x2, $y2) = GetWindowRect($id[0]);
my $img = CaptureRect($x1,$y1, $x2-$x1,$y2-$y1);
$img->Write("x.png"); # save
system("start x.png"); # view
28. Win32::GuiTest::SendMouse($command)
{LEFTDOWN} left button down
{LEFTUP} left button up
{MIDDLEDOWN} middle button down
{MIDDLEUP} middle button up
{RIGHTDOWN} right button down
{RIGHTUP} right button up
{LEFTCLICK} left button single click
{MIDDLECLICK} middle button single click
{RIGHTCLICK} right button single click
{ABSx,y} move to absolute coordinate
{RELx,y} move to relative coordinate
38. FAQ. 役に立つの?
新しいスクリーンセーバーとして鑑賞する
Fun of the New Screen Saver
タイピングソフトでハイスコアを出す
Scoring champion for Key-Typing software
Windowsアプリの自動テスト化
Automation Testing for Win32 Applications
セキュリティ脆弱性検査
Fuzzing
その他 etc.
49. How to Kill the process on Win32
XP, 2003 Server …
New command line tools
tasklist
プロセスを一覧表示する
taskkill /F /IM notepad.exe
プロセスを kill する
成功: プロセス "notepad.exe" (PID 777) は強制終
了されました。