Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Writting and reading from windows applications

by mineiro (Novice)
on Sep 20, 2004 at 20:03 UTC ( [id://392475]=perlquestion: print w/replies, xml ) Need Help??

mineiro has asked for the wisdom of the Perl Monks concerning the following question:

I'm using a application for windows, maybe Delphi app I don't know, this application receive two input fields. When I fill these fields and do ENTER, the application show another field, the answer. I want, automatically, fill those two fields and read the third, the answer. Can you help me? Thanks!
  • Comment on Writting and reading from windows applications

Replies are listed 'Best First'.
Re: Writting and reading from windows applications
by shenme (Priest) on Sep 20, 2004 at 21:24 UTC
    I haven't done this in a long while and I know there are new modules to make this easier. I searched at search.cpan.org using "win32 ui" and saw these modules mentioned:

    Win32::GuiTest - looks interesting, although ActiveState only has an old old version (1.3 vs. 1.5)

    Win32::CtrlGUI uses Win32::Setupsup and also looks interesting

    Maybe you could use "Super Search" on some of these names to find other postings on PM?

      Yes, Win32::GuiTest can do this. I was interested by your post and have tried the procedure with the module and it works, though it's a bit of a fiddle to get it sat up right the first time around..

      I used handler 1.5 to lookup the different widgets classnames, Control IDs, Texts, handles etc. A Must-have tool for this operation.

      Here is some code for what I did. I've got this app that shows a registration nag-screen each time it starts. I wanted to fill in some dummy data and then close the nag window.

      use strict; use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWi +ndow SendKeys GetChildWindows GetClassName GetPar +ent); #Get our "mainwindow" - various search criteria can can be used. #FindWindowLike ($window,$titleregex,$classregex,$childid,$maxleve +l) my @windows = FindWindowLike(0, qr/Iris License Registration/i,und +ef,undef,); #Go through all widgets and sort out the ones we're interested i +n for (@windows) { #Mainwindow has no parents..here we start if (! GetParent($_) ) { #dumps all children widget handles my @chld = GetChildWindows($_); #Dump handles to the two text-input fields we want #We lookup the classname for the widgets with handWler1 +.5, which is 'Edit' my @text_field; for (@chld) { #Get handle to the empty text-input fields if ( (GetClassName($_) =~ m/Edit/) && (GetWindowText($ +_) eq '') ) { push @text_field,$_; } } #Now we have handles to widgets we wanna manipulate.. #We insert text into the two input fields ("Registered To" + and "Licence Key") #Get text field we wanna manipulate in the foreground. A +ctivates windows and widget.. SetForegroundWindow($text_field[0]); #Hm..WaitWindowLike() wouldn't not work..Not exported an +d not defined.. ??! #..instead we just wait a little, just in case.. select (undef,undef,undef,0.50); #The "crux"..nice. Also we use 50 ms delay between each + key input. SendKeys("Joe Doe",50); #Go to next text-field, "serial nr field"...{TAB} key co +uld have been used instead.. SetForegroundWindow($text_field[1]); SendKeys("12345678acme{ENTER} ",50); last; } }

      The module installs without problems with ppm on perl 5.8.3 build 809.

Re: Writting and reading from windows applications
by punkish (Priest) on Sep 20, 2004 at 21:16 UTC
    Your question has very little chance of being answered helpfully because the question itself is not very clear.

    Is your application a native Windows application (probably so, since you say it is a Delphi app)? If so, what does it have to do with Perl?

    If you want to use Perl to fill in input fields in a Delphi app and read the result of that action from yet another field, you have to provide more information on how your Delphi app is going to interact with Perl. Does your app write out the info to a file on the disk that you could read? Is there some other interprocess communication possible?

Re: Writting and reading from windows applications
by mineiro (Novice) on Sep 23, 2004 at 23:43 UTC
    Thank you very much guys! I make some tests using Win32::GuiTest and working fine!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://392475]
Approved by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found