http://www.perlmonks.org?node_id=197248


in reply to TWAIN Issues and Perl

In the spirit of TMTOWTDI, you could also look at the Win32::API module, and do API calls to achieve most anything. There is an online API reference (including messages for the SendMessage API I used) at http://www.vbapi.com

Here's a small example I whipped up to experiment myself. Note that you will have to open Calculator in "scientific mode" for this script to work.

#! C:/perl/bin/perl -w use strict; use Win32::API; use vars qw($rv); use constant BM_CLICK => hex('F5'); my $findwindow = new Win32::API("user32", "FindWindowA", ['P','P'], 'N'); my $findwindowex = new Win32::API("user32", "FindWindowExA", ['N','N','P','P'], 'N'); my $sendmessage = new Win32::API("user32", "SendMessageA", ['N','N','N','P'], 'N'); my $setactivewindow = new Win32::API("user32", "SetActiveWindow", ['N'], 'N'); # Find the handle of the parent window. In this case # 'Calculator' is the text shown in the title bar my $hwnd = $findwindow->Call( 0,'Calculator'); print "Parent window handle = $hwnd\n"; # Find the handle of the buttons we want to press. # Sometimes, but not always, the caption shown on the button my $hex_button = $findwindowex->Call($hwnd, 0, 0, 'Hex'); my $dec_button = $findwindowex->Call($hwnd, 0, 0, 'Dec'); my $oct_button = $findwindowex->Call($hwnd, 0, 0, 'Oct'); my $bin_button = $findwindowex->Call($hwnd, 0, 0, 'Bin'); $rv = $setactivewindow->Call($hwnd); print "setactivewindow returned = $rv\n"; foreach ($hex_button,$dec_button,$oct_button,$bin_button) { $rv = $sendmessage->Call($_ , BM_CLICK, 0, 0); print "sendmessage returned = $rv\n"; sleep 2; }


ryddler