Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: TWAIN Issues and Perl

by ryddler (Monk)
on Sep 12, 2002 at 15:34 UTC ( #197248=note: print w/replies, xml ) Need Help??

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

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; }


Replies are listed 'Best First'.
Re: Re: TWAIN Issues and Perl
by Mr. Muskrat (Canon) on Sep 12, 2002 at 17:34 UTC

    ++ for showing the hard way of doing things ;)

    Win32::Guitest makes it easier to do the same API calls... This program does the same thing without all of the return messages. (I didn't see the point for this simple exercise.)

    Start calculator before running this code (mode doesn't matter)

    #! C:/perl/bin/perl use strict; use warnings; # Win32::GuiTest doesn't like -w use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys Push +Button); my @windows = FindWindowLike(0, "^Calculator"); # find all calculator +windows die "Start Calc before running this example.\n" unless @windows; my $hwnd = $windows[0]; # we'll just the first match SetForegroundWindow($hwnd); # Bring it the foreground SendKeys("%VS"); # switch to scientific mode # press these buttons foreach my $button ("Hex", "Dec", "Oct", "Bin") { sleep(2); PushButton($button); }
    See how much simpler that is? Win32::API is great if it can't be done another way.

    Update: Added the die statement to my code.

Re^2: TWAIN Issues and Perl
by Anonymous Monk on Apr 14, 2010 at 21:32 UTC
    How about passing a ALT-G or CTRL-G to the window??
    THis is soooo close to what I need.
    I am digging....

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://197248]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-03-28 05:37 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (327 votes). Check out past polls.