Link to home
Start Free TrialLog in
Avatar of turn123
turn123Flag for United States of America

asked on

Win32::GuiTest sends | instead of \ for a random amount charecters.

I'm not sure what is wrong but the output of the code below will be anything from \\server\d\Jonathan\invoice.pdf to ||SERVER|D|jONAthan\\invoice.pdf

What is the problem and how do I fix it?

Thank you,
Turn123

##      Open and print PDF
SendKeys("{LWIN}r");
SendKeys("\\\\server\\d\\Jonathan\\invoice.pdf~");
sleep 2;
SendKeys("^p~");
sleep 5;
Avatar of turn123
turn123
Flag of United States of America image

ASKER

Full code:

###      Extracts the shipping and notification information from quickbooks

use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys);
      $Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode
use Win32::GUI;
use strict;

##      Check to see if our import file exists.
if (-e 'import.txt') {
      #      If it doesn't we create a new one.
      open CREATE, "> \\\\shipping\\data import\\import.txt";
      close CREATE;
} else {
      #      If it does we do nothing. (under development)
      open CREATE, "> \\\\shipping\\data import\\import.txt";
      close CREATE;
};

##      We delete all the html and pdf files left over from the last run
while (my $line = <*>) {
      unlink $1 if $line =~ /(.*\.html)/i;
      unlink $1 if $line =~ /(.*\.pdf)/i;
};

##      Defining the varibales
my $line="";
my $a=0;
my $b=1;
my @invoice=();
my @baddress=();
my @saddress=();
my @PO=();
my @carrier=();
my @partnumber=();
my @quantity=();
my @priceeach=();
my @price=();
my @description=();
my @email=();

##      Give QuickBooks Focus
my @windows = FindWindowLike(0, "^Osborne Wood Products, Inc - QuickBooks");
for (@windows) {
      Win32::GUI::Maximize($_);
      SetForegroundWindow($_);
      SendKeys("%ffi");                              ##       We batch print the invoice form
      sleep 6;                                    #      Wait for the invoices to load
      SendKeys("~");                                    #      Hit enter
      sleep 5;                                    #      Wait for the print screen
      SendKeys("p%c");                              #      Change the printer to the pdf printer and go to the number of copies
      SendKeys("1");                                    #      And set it to 1
      sleep 2;                                    #      Wait for it to take the change
      SendKeys("~");                                    #      And print
      ##      Giving script focus
      @windows = FindWindowLike(0, "Invoice Importer");
      for (@windows) {
            print "$_>\t'", GetWindowText($_), "'\n";
            SetForegroundWindow($_);
      };
      system 'pause';                                    #      Manual breakpoint for user to continue when all documents are printed
};

sleep 1;
##      Open the PDF Editor and converts the pdf file to html documets
SendKeys ("{LWIN}rC:\\pdf995\\res\\utilities\\pdfEdit995\.exe~");
sleep 4;
SendKeys ("^{TAB 9}{TAB 4}~{TAB}~invoice.pdf~{TAB 3}~invoice.html~");

##      Clean up after ourselves
while (1) {
      my $flag = "";
      @windows = FindWindowLike(0, "^Intuit");
      for (@windows) {
            $flag = 1;
      };
      last if $flag == 1;
      sleep 2;
};
SendKeys ("%{F4}%{F4}%{F4}");                        #      Closes html index and PDF editor
sleep 1;

##      Open and print PDF
SendKeys("{LWIN}r");
SendKeys("\\\\server\\d\\Jonathan\\invoice.pdf~");
sleep 2;
SendKeys("^p~");
sleep 5;
ASKER CERTIFIED SOLUTION
Avatar of ctrondlp
ctrondlp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of turn123

ASKER

ctrondlp,

>1) Make sure the shift key is working correctly (i.e. isn't stuck).
First think I tried.

>2) Try typing the key sequence (\\server\....) manually and see if the same problem (||SERVER|D|....) persists.  
It doesn't happen if you type it in manually.

>3) You could even beef-up the script by replacing many of the SendKeys() statements with better Win32::GuiTest commands (i.e., WMSetText, MenuSelect, WaitWindow, etc.; which are available in Win32-GuiTest-ad v1.50.1 (http://sourceforge.net/projects/winguitest))
>4) And lastly, an initial script recorder for Win32::GuiTest can be found at http://dkp.itgo.com...  It is still in development, but it might help in certain cases.
These look interesting.  I'll look into them as soon as I get a chance and let you know what I come up with.

Thanks for taking the time to look at this.

Turn123
Avatar of turn123

ASKER

Dennis,

When trying to install I'm getting Error: no suitable installation target found for package Win32-GuiTest.

ppm> install C:\Downloads\Win32-GuiTest-1.50.1-ad\win32-guitest.ppd
Error: no suitable installation target found for package Win32-GuiTest.

What should I do differently?

Turn123
Avatar of turn123

ASKER

Dennis,

Any suggestions on how I can install the package to see if it solves my problem?

Turn123
Avatar of turn123

ASKER

I'm asking for this to be deleted as I never heard back from Dennis.

Turn123
Avatar of ctrondlp
ctrondlp

You could try using v5.6.1 of Perl that supports Win32-GuiTest-1.50.1-ad or you could use v5.8.x of Perl and use Win32-GuiTest-1.50.2-ad...  Or you could use the build instructions included in the README to manually install it.  Easy as pie. :-)


Once you get things going and for some odd/out-of-the-ordinary reason it still appears to use the shift modifier on characters (\ becomes |), try adding the following line several places within your script: SendRawKey(VK_LSHIFT, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP);


-D
Avatar of turn123

ASKER

> Easy as pie. :-)
Yeah right :-(.

I actualy got it to do what I wanted using the Win32::Clipboard module which seems like a better solution.

Turn123