用 PERL WIN32-setupsup Module 開個軟體



贊助商連結


bx2aa
2004-03-18, 05:21 PM
以下是列出所有程式
然後在裡面找包含 「開始」功能表 就送 SendKeys 那一堆按鍵給這時的 $whandle

#! c:\perl\bin\perl.exe -w

use Win32::Setupsup;
use Win32::IProc;
# get the list of windows
Win32::Setupsup::EnumWindows(\@windowlist) or die "process list error: ".Win32::Setupsup::GetLastError( )."\n";

foreach $whandle (@windowlist){
if (Win32::Setupsup::GetWindowText($whandle,\$text)){
print "$whandle: $text","\n";
if ($text =~ m/「開始」功能表/) {
Win32::Setupsup::SendKeys($whandle,"\\CTRL+\\\\ESC\\\\CTRL-\\\\SHIFT+\\P\\SHIFT-\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\DN\\\\RET\\\\UP\\\\RET\\",1,0);
}
}
else {
warn "Can't get text for $whandle" .
Win32::Setupsup::GetLastError( )."\n";
}
}

foreach $windows (@windows) {
$pobj = new Win32::IProc;

$pobj->Open($windows,PROCESS_QUERY_INFORMATION,INHERITED,\$handle) or warn "Can't get handle:".$pobj->LastError( )."\n";

# DIGITAL = pretty-printed times
$pobj->GetStatus($handle,\$statusinfo,DIGITAL);

$pobj->CloseHandle($handle);

while (($procname,$value)=each %$statusinfo){
print "$procname: $value\n";
}
print "\n\n\n\n\n\n";
}

# turn window handle list into a hash
# NOTE: this conversion populates the hash with plain numbers and
# not actual window handles as keys. Some functions, like
# GetWindowProperties (which we'll see in a moment), can't use these
# converted numbers. Caveat implementor.
for (@windowlist){$windowlist{$_}++;}

# check each window for children
foreach $whandle (@windowlist){
if (Win32::Setupsup::EnumChildWindows($whandle,\@children)){
# keep a sorted list of children for each window
$children{$whandle} = [sort {$a <=>$b} @children];

# remove all children from the hash, we won't directly
# iterate over them
foreach $child (@children){
delete $windowlist{$child};
}
}
}

# iterate through the list of parent or childless windows and
# recursively print each window handle and its children (if any)
foreach my $window (sort {$a <=> $b} keys %windowlist){
&printfamily($window,0);
}

# print a given window handle number and its children (recursively)
sub printfamily {
# starting window, how deep in a tree are we?
my($startwindow,$level) = @_;

# print the window handle number at the appropriate indentation
print((" " x $level)."$startwindow\n");

return unless (exists $children{$startwindow}); # no children, done.

# otherwise, we have to recurse for each child
$level++;
foreach $childwindow (@{$children{$startwindow}}){
&printfamily($childwindow,$level);
}
}

其他還顯示目前有哪些 Process.

這是多平台系統管理這本書內的程式碼, 我只是複製貼上, 在加個 SendKeys

Setupsup 比 QuickMacro 好的地方是不用設定等待時間.
如果使用 QuickMacro 沒有等待的話可能會點到其他程式.