use Win32::Clipboard; use Win32::GuiTest qw/SendKeys/; while(1) { my @time = localtime(time); my $file = sprintf "20%02d_%d_%d_%d_%d_%d.bmp", $time[5]%100, $time[4]+1, $time[3], $time[2], $time[1], $time[0]; my ($try_count, $screen) = (30, undef); SendKeys('{PRTSCR}');#调用键盘的print_screen这个键 $screen = Win32::Clipboard::GetBitmap();#print_screen这个键会截图,存储在内存中,然后用这个剪切板来保存文件 if ($screen) { open BITMAP, "> $file" or die; binmode BITMAP; print BITMAP $screen; #在这里将截屏的内容写入文件 close BITMAP; } sleep(15); }