Jump to content

MouseClick works in .au3 script but fails in same script compiled to .exe


Recommended Posts

I am using Autoit to transfer information between 2 programs and have written a script that works well when run as a .au3 script but appears to stop at a MouseClick instruction when compiled to a .exe file.

The MouseClick command is being used to activate a control  that was previously activated using SEND("!q") before a program update eliminated a keyboard shortcut. I have not been able to use ControlClick due to the absence of a identifiable control in the program.

What would prevent this working as an exe when it performs well in a script?

Link to comment
Share on other sites

Hello,

Could you post your complete script ? 

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=nurse.ico
#AutoIt3Wrapper_Outfile=Nurses6.exe
#AutoIt3Wrapper_Outfile_x64=Nurses6.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Nurses
;
;
;Script for use with ZedMed Clinical Module
;   Used to speed the entry of patients into the treatment room waiting room
;   when transferring their care to the registered nurses
;
;Author : Ross Newbery
;Version 1.0
;Date 20/5/2009
;Version 1.1 updated to cope with minor change in field labels introduced by ZedMed update 19
; Date 9/4/2013
;Version 1.2 updated to fix intermittent failures to pick up surname field and occ failures to select Registered Nurse as "doctor" in waiting room attendance dialog
; Date 12/4/2013
;Version 1.3 Added multiple WinWaitActive Statements in the patient Data section to improve reliability
;This eliminated the need for multiple Sleep statements
; Date 29/11/2017
;Version 1.4 Edited to restore function after ZedMed version 27 update broke script with multiple dialog box channges
;Currently works as script but fails when compiled as exe
;Date 14/9/2018
;Version 1.4 Edited to restore sleep statements to get reliable name data collection
;Version 1.6 Edited to restore function when Zedmed Version 30 update broke script
;activate clinical module
If WinExists("Zedmed Clinical") Then
    WinActivate("Zedmed Clinical", "")
    WinWaitActive("Zedmed Clinical", "")
    Else
    MsgBox(0, "Nurses Waiting Room", "ZedMed Clinical does not appear to be open")
    Exit
    EndIf
;open the patient data section (through arcane kludge due to lack of direct hotkey access)
Send ("^h")
;move to the section tabs after  a small pause - exra pauses added 11/4/2013 to avoid unresponsiveness
WinWaitActive("Patient - ", "");WinWaitActive (with default window matching mode) appears to work more reliably than multiple "Sleep" parameters
sleep(200)
Send ("{TAB}")
sleep(200)
WinWaitActive("Patient - ", "")
Send ("{TAB}")
sleep(200)
WinWaitActive("Patient - ", "")
Send ("{TAB}")
;a small delay here seems to stop unpredictable results
sleep(200)
WinWaitActive("Patient - ", "")
;move left to the patient info tab
Send ("{LEFT 2}")
;another delay to stop weirdness
Sleep (200)
WinWaitActive("Patient - ", "")
;move to the first name field
Send ("{TAB 2}")
WinWaitActive("Patient - ", "")
;Sleep (500)
;initialise the variable to make it obvious if bad stuff is happening to the script
$first = "wrong"
;get the first name
$first = ControlGetText ( "Patient", "", "[CLASS:TDBEdit; INSTANCE:15]")
;add a comma and space before the first name - this is for new incarnation of Medipak -
;$first = ", " & $first
;initialise this variable too
$last = "wrong2"
WinWaitActive("Patient - ", "")
;move to the last name field
Send ("{TAB 3}")
WinWaitActive("Patient - ", "")
; get the last name
$last = ControlGetText ( "Patient", "", "[CLASS:TDBEdit; INSTANCE:13]")
WinWaitActive("Patient - ", "")
;close patient data section
Send ("!c")
;check if Appointments open and close if it is
If WinExists("Appointments Display Grid - Auto-refresh every 1 minutes") Then
    WinActivate("Appointments Display Grid - Auto-refresh every 1 minutes", "")
    WinWaitActive("Appointments Display Grid - Auto-refresh every 1 minutes", "")
    Send ("!{F4}")
EndIf
;Activate the waiting Room
If WinExists("Waiting Room - Auto-refresh every 30 second") Then
    WinActivate("Waiting Room - Auto-refresh every 30 second", "")
    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
    ;or open it if it is not already open
ElseIf WinExists("Uni. Of Canberra Medical Centre") Then
    WinActivate("Uni. Of Canberra Medical Centre", "")
    Send ("!w")
    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
    ;or if that doesn't work notify the user that bad stuff is happening
;Else
;   MsgBox(0, "Nurses Waiting Room", "ZedMed does not appear to be open" & @CRLF & "Please check to make sure there are no message dialogs " & @CRLF & "that require closing")
EndIf
;Now to clear the decks of rubbish -
;If that bloody Intramail box is active get rid of it
If WinExists("Confirm") Then
    WinActivate("Confirm", "")
    WinWaitActive("Confirm")
    ;click "No"
    ControlClick("Confirm", "", "[CLASS:TButton; INSTANCE:1]")
    ;make sure the waiting room is active after that
    WinActivate("Waiting Room - Auto-refresh every 30 second", "")
    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
EndIf


;and death to the Office Tray! Damn the torpedoes!  (Watch out for complaints that this closes important stuff)
;but for some unexplained reason this subroutine blocks execution of the script - there may be difficulty in determining whether
; the Office Tray window exists or not
;If WinExists("Office Tray")Then
;   WinActivate("Office Tray", "")
;   WinWaitActive("Office Tray")
;   ;Close it
;   Send ("!{F4}")
;   If WinExists("Message Dialog") Then
;       Send ("!y")
;       EndIf
;   EndIf
;activate the Quick Attend Button (via mouseclick because some dropkick programmer eliminated the keyboard shortcut)
   WinActivate("Waiting Room - Auto-refresh every 30 second", "")
    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
MouseClick("Left",45,55)
    ;Send ("!q");if keyboard shortcut reinstated this may be more robust than mouseclick
    ;Find the patient
    WinWaitActive("Find / Add Patient")
    ;enter the last name
    WinActivate("Find / Add Patient")
       Send ("{HOME}")  ;this extra keystroke appears to fix the problem of missing initial characters
       ControlSend("Find / Add Patient", "", "[CLASS:TEdit; INSTANCE:3]", $last)
    ;enter the first name;
    WinActivate("Find / Add Patient")
        Send ("{HOME}") ;this extra keystroke appears to fix the problem of missing initial characters
       ControlSend("Find / Add Patient", "", "[CLASS:TEdit; INSTANCE:2]", $first)
    ;find patient and check it is the right one
    ;search
Send("!f")
;wait till the result has been checked by the user and the attendance details screen has appeared
WinWaitActive("Attendance Details")
;pause to allow other script to complete
Sleep(1000)
;Select the "Doctor" Selector Combo box
ControlClick("Attendance Details", "", "[CLASS:TKeyComboBox; INSTANCE:4]")
;scroll down
ControlCommand("Attendance Details", "", "[CLASS:TKeyComboBox; INSTANCE:4]","ShowDropDown", "")
;select registered nurse
ControlCommand("Attendance Details", "", "[CLASS:TKeyComboBox; INSTANCE:4]","SetCurrentSelection", 10)
ControlClick("Attendance Details", "", "[CLASS:TKeyComboBox; INSTANCE:4]")
;Send("{ENTER}");not needed - this breaks script
Send("r");insurance to make sure that "Registered Nurse" is selected
;and confirm selection
;Send("{ENTER}");appears this keystroke send is unnecessary after sending the "r"
;select Notes field for entry of instructions
ControlClick("Attendance Details", "", "[CLASS:TDBMemo; INSTANCE:1]")
;go up in case there is more than one line in the details field
Send ("{UP}")
;and back home for entry
Send ("{HOME}")
;and do it again because sometimes it doesn't work the first time
Send ("{HOME}")
Exit

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

When i read your script i presum you're stuck becose of a winwait. 

 

The thing you can do in this case is do some msgbox to spot where you're stuck and work on it. 

 

You could do this and detect where you're stuck and give us feedback. Replace this portion of code : 

MsgBox(0,"Debug","Debug BEFORE CONFIRM");=============================DEBUG

If WinExists("Confirm") Then
MsgBox(0,"Debug","Debug DURING CONFIRM");=============================DEBUG

    WinActivate("Confirm", "")
    WinWaitActive("Confirm")
MsgBox(0,"Debug","Debug CONFIRM DETECTED ACTIVATED");=============================DEBUG

    ;click "No"
    ControlClick("Confirm", "", "[CLASS:TButton; INSTANCE:1]")
    ;make sure the waiting room is active after that
    WinActivate("Waiting Room - Auto-refresh every 30 second", "")
    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
MsgBox(0,"Debug","Debug WAITING ROOM DETECTED ACTIVATED");=============================DEBUG

EndIf

MsgBox(0,"Debug","Debug Trying to detect waiting room 2");=============================DEBUG

    WinWaitActive("Waiting Room - Auto-refresh every 30 second", "")
MsgBox(0,"Debug","Waiting room 2 detected | now cliking.");=============================DEBUG

    MouseClick("Left",45,55)
    ;Send ("!q");if keyboard shortcut reinstated this may be more robust than mouseclick
    ;Find the patient
    WinWaitActive("Find / Add Patient")

Also you can have windows issues becose of admin rigths. Guess it's not the case in your script but to be sure you can try one time

#requireAdmin

at the top of your script.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Developers
9 minutes ago, Frogdoggle said:

This works after clicking through the Debug dialogs but as mentioned in the original post my script code works properly when run as a script but when compiled into an exe it appears to stop just before the MouseClick command.

... and SciTE doesn't run elevated? 
Do you compile the script as x64 or x86?

To check at which statement it is waiting: Add the following statement in your script, compile, run and hover of the TrayIcon to see which statement it is "hanging".

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info

Let us know what you find.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Jos

No I am not running SciTe elevated

I think I am compiling to x64  (Win 10 64 bit)

running compiled script with elevation appears to allow it to progress past the MouseClick command but with a data collection problem.  I

I have to leave this problem for today but will look at it again on Monday

Thank you very very much for your interest and help.

Link to comment
Share on other sites

  • Developers
Just now, Frogdoggle said:

I think I am compiling to x64  (Win 10 64 bit)

That should be shown in the SciTE Output Pane when you do a Compile. Also the AutoIt3 version when doing a Run will be shown there. Just wondering whether that is the difference.

Jos :) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

47 minutes ago, Jos said:

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info

@Jos sorry if i pointed him out on the worst way to do that xD

I ll try this out to point other on it :) 

 

Edit: 

Wooot! 

image.png.941c51f5f672b8e90c04bb927a5217e5.png

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Thank you for help and guidance.  It induced me to think harder and tinker longer and after some effort and the reinstallation of the most recent full version of SciTE4AutoIt3

both the .au3 script and the compiled .exe versions now work.  Jos' comment about the SciTe output pane made me realize my embarrassing mistake.  Thank you for your uncritical and patient help for people who don't really know what they are doing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...