use strict; use warnings; use feature 'say'; use Cwd 'cwd'; use File::Spec::Functions 'catfile'; use Win32::GuiTest qw( WaitWindow SendMessage AllocateVirtualBuffer WriteToVirtualBuffer FreeVirtualBuffer SetForegroundWindow SendKeys PushButton ); my $WM_DROPFILES = 0x233; my $pid = system 1, 'mspaint.exe'; my ( $h ) = WaitWindow( ' - Paint' ); for ( <*.jpg> ) { # I have a few JPGs in cwd. next if /flipped/; # Seen, skip. my $drop = pack 'LLLCCZ*x', 14, 0, 0, 0, 0, catfile cwd, $_; my $buf = AllocateVirtualBuffer( $h, length $drop ); WriteToVirtualBuffer( $buf, $drop ); SendMessage( $h, $WM_DROPFILES, $buf-> { ptr }, 0 ); FreeVirtualBuffer( $buf ); SetForegroundWindow( $h ); SendKeys( '%(hrov)' ); # Alt-Home, Rotate, Vertical_flip. # You like your pictures upside down, don't you. SendKeys( '%(fa)' ); # Alt-File, Save As. WaitWindow( 'Save As' ); s/(?=.jpg$)/_flipped/; unlink; # Overwrite! Avoid needless idle questions. SendKeys( $_, 1 ); PushButton( '&Save' ); sleep 1; # To prevent next file dropped when app still # not sure if current file was saved. } SendKeys( '%{F4}' ); # Alt-F4, of course. No need to kill $pid. __END__