Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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


Comment on Re: TWAIN Issues and Perl
Download Code
Re: Re: TWAIN Issues and Perl
by Mr. Muskrat (Abbot) 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....
    Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://197248]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (18)
As of 2014-07-31 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls