本帖最后由 523066680 于 2015-3-19 12:02 编辑
刚刚试了一下,没有做文件名冲突判断(Snap1.bmp Snap2.bmp Snap3.bmp....),再执行一次的时候会将上次的截图覆盖。
有闲情了再改吧。- =info
- Via 523066680 @ bathome.net
- 2015-03
- =cut
-
- use Win32::Clipboard;
- use Term::ReadKey;
- use Time::HiRes qw/sleep/;
- use IO::Handle;
- STDOUT->autoflush(1);
-
- my $Fold = "D:\\Snap";
- my $i = 0;
- my $clip = Win32::Clipboard->new();
- $clip->Empty();
- mkdir $Fold unless (-e $defult);
-
- my $timesec = ×ec();
-
- while (1) {
- $image = $clip->GetBitmap();
- if ($image) {
- $i++;
- print "Catch one!\n";
- &savepic("$timesec $i.bmp", \$image);
- $clip->Empty();
- }
- &keyout();
- sleep 0.2;
- print ".";
- }
-
- sub savepic {
- my ($name, $rdata) = (shift, shift);
- open BITMAP, ">$Fold\\$name";
- binmode BITMAP;
- print BITMAP ${$rdata};
- close BITMAP;
- }
-
- sub keyout {
- my $key;
- $key = ReadKey(-1);
- if ( ord($key) == 27 ) {
- print "Quit";
- sleep 1.0;
- exit;
- }
- }
-
- sub timesec {
- my ($sec,$min,$hour,$day,$mon,$year) = localtime();
- return
- sprintf (
- "%02d-%02d %02d.%02d.%02d",
- $mon, $day, $hour, $min, $sec
- );
- }
复制代码 按Prt Screen键截图,自动保存到D盘snap文件夹。
按Esc 键退出。
执行输出类似这样:
──────────┐
.......Catch one! │
....Catch one! │
..........Catch one!│
....Catch one! │
.......Quit │
──────────┘
命名格式为 月-日 时.分.秒 序号.bmp |