Jump to content

Help needed to Optimize Script for Newbie!


Recommended Posts

Hello and thanks for looking at my post.

I have just cobbled together my first script which basically opens 2 applications at startup (it is placed in the Startup folder) and then sends a few commands to them.

It does work, but I need it to be as reliable as possible and really I don't kniow what i'm doing.

If anyone could give me the benefit of their experience I'd be very greatful.

The two apps are GlovePIE and Vjamm

Here's the script with comments:

$file = "C:\Program Files\GlovePIE\vjammascript.PIE"

Run(@ComSpec & ' /c start "" "' & $file & '"', "", @SW_HIDE) **Opens my Glove PIE script. This intercepts a couple of keys and sends midi messages to Vjamm

WinWait("GlovePIE - Programmable Input Emulator 0.29") **Does this wait for the window to be ready before proceeding? I hope so.

Send("{F9}") **This runs the script

Run ("C:\Program Files\VJamm 3\VJamm3.exe")

WinWait("VJamm 3") **There are 2 windows called this which is confusing me a bit. One is hidden to the user but i found it when maximizing it.

WinWait("Secondary Output")

Opt("WinTitleMatchMode", 4)

WinWaitActive("[CLASS:TfmVJamm3main]", "") **I'm not sure if this is working

MouseClick("left", 226, 343, 2) **This is because I couldn't get the window I wanted in focus so faked clicking on it.

ControlClick("Vjamm 3", "", "[CLASS:TVJammTransTab; TEXT:Patches]")

Sleep(300) ** This is because the next command (below) doesn't always work and this delay seems to improve it.

MouseClick("left", 154, 469, 4) **Opens a file in a custom browser windo

Sleep(2000)

MouseClick("left", 782, 611, 1) ** Clicks a custom control

Sleep(1000)

Send("{Tab}") ** Enables Full Screen Mode

I'm not sure if this makes any sense or if I have provided enough info.

I'm wondering if:

I should include any error checking

If using the mouse click technique is a bit flakey (I have ensured the app always opens in the same position but maybe I should check this?)

If there is a better way than using Sleep i.e checking if the previous command has actually finished yet.

Or maybe I should but a delay between all commands to improve reliabilty?

Speed isn' t an issue. Just needs to start automatically.

Thanks for looking. Any questions please ask,

Gavin

www.digitalfunfair.co.uk

Link to comment
Share on other sites

Hmmm, where to begin?

I know, welcome to the forum!

I'm not so good at adding a lot of error checking, but I can mention some different (and maybe better) ways to skin this cat. [Although, I have no use for a skinned cat.]

I would suggest that you change this:

$file = "C:\Program Files\GlovePIE\vjammascript.PIE"

Run(@ComSpec & ' /c start "" "' & $file & '"', "", @SW_HIDE)

to:

ShellExecute("C:\Program Files\GlovePIE\vjammascript.PIE")

It is just easier/cleaner...

Change:

WinWait("GlovePIE - Programmable Input Emulator 0.29")

to

WinWait("GlovePIE - Programmable Input Emulator 0.29", "text")

WinActivate("GlovePIE - Programmable Input Emulator 0.29", "text")

WinWaitActive("GlovePIE - Programmable Input Emulator 0.29", "text")

where text equals some unique text that shows up in the window only when the application (app) is "ready".

Change:

Send("{F9}")

to a ControlFocus/ControlSend - if they work with the app of interest.

This line is okay:

Run ("C:\Program Files\VJamm 3\VJamm3.exe")

[Although, some would say that you should always include the working directory.]

It is better to use some "window text" and I probably go overboard with my WinWait, WinActivate and WinWaitActive trio of lines, but those three lines of code also add a slight delay into your script - which might help you. AutoIt pauses about 250 milliseconds after most WinXxxxxx functions (unless you change that amount via the WinWaitDelay Opt setting) so, that trio of lines adds just under a second delay for the window "to be ready" for your next input.

WinWait("VJamm 3", "text")

Same comments as above:

WinWait("Secondary Output", "text")

You do not need the window of interest to be in focus if you are going to be using only "ControlXxxxx" functions or mouse clicks relative to the desktop/screen: [Caveat - upgrade to AutoIt v3.2.4.0 if you haven't already.]

Opt("WinTitleMatchMode", 4)

WinWaitActive("[CLASS:TfmVJamm3main]", "")

Whatever works for you, but see comment above:

MouseClick("left", 226, 343, 2)

ControlClick returns a value, you can check it during debug:

ControlClick("Vjamm 3", "", "[CLASS:TVJammTransTab; TEXT:Patches]")

$ret = ControlClick("Vjamm 3", "", "[CLASS:TVJammTransTab; TEXT:Patches]")

MsgBox(0, "", $ret)

...or use a ConsoleWrite and run the script from within SciTE.

It is best not to rely on Sleep lines - but sometimes you have too:

Sleep(300)

maybe a ControlCommand checking for "IsEnabled" as in

Do

Sleep(100)

Until ControlCommand.......

A ControlClick or ControlFocus/ControlSend might do better here:

MouseClick("left", 154, 469, 4)

Maybe a WinWait with some unique text instead:

Sleep(2000)

A ControlClick or ControlFocus/ControlSend might do better here:

MouseClick("left", 782, 611, 1)

Maybe a WinWait with some unique text instead:

Sleep(1000)

A ControlClick or ControlFocus/ControlSend might do better here:

Send("{Tab}")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Thanks alot for taking the time to help out. I really appreciate it.

Some useful hints there.

Alot of my problems (using mouse clicks) stem from the fact that I couldn't access many of the controls in Vjamm. They seem to have a different ID and/or instance no every time I open the software

Similarly the sleep function was used 'cos I couldn't find a way of telling if an event had occurred.

Using text is a top tip though.

Thanks alot,

Gavin

www.digitalfunfair.co.uk

Hmmm, where to begin?

I know, welcome to the forum!

I'm not so good at adding a lot of error checking, but I can mention some different (and maybe better) ways to skin this cat. [Although, I have no use for a skinned cat.]

I would suggest that you change this:

$file = "C:\Program Files\GlovePIE\vjammascript.PIE"

Run(@ComSpec & ' /c start "" "' & $file & '"', "", @SW_HIDE)

to:

ShellExecute("C:\Program Files\GlovePIE\vjammascript.PIE")

It is just easier/cleaner...

Change:

WinWait("GlovePIE - Programmable Input Emulator 0.29")

to

WinWait("GlovePIE - Programmable Input Emulator 0.29", "text")

WinActivate("GlovePIE - Programmable Input Emulator 0.29", "text")

WinWaitActive("GlovePIE - Programmable Input Emulator 0.29", "text")

where text equals some unique text that shows up in the window only when the application (app) is "ready".

Change:

Send("{F9}")

to a ControlFocus/ControlSend - if they work with the app of interest.

This line is okay:

Run ("C:\Program Files\VJamm 3\VJamm3.exe")

[Although, some would say that you should always include the working directory.]

It is better to use some "window text" and I probably go overboard with my WinWait, WinActivate and WinWaitActive trio of lines, but those three lines of code also add a slight delay into your script - which might help you. AutoIt pauses about 250 milliseconds after most WinXxxxxx functions (unless you change that amount via the WinWaitDelay Opt setting) so, that trio of lines adds just under a second delay for the window "to be ready" for your next input.

WinWait("VJamm 3", "text")

Same comments as above:

WinWait("Secondary Output", "text")

You do not need the window of interest to be in focus if you are going to be using only "ControlXxxxx" functions or mouse clicks relative to the desktop/screen: [Caveat - upgrade to AutoIt v3.2.4.0 if you haven't already.]

Opt("WinTitleMatchMode", 4)

WinWaitActive("[CLASS:TfmVJamm3main]", "")

Whatever works for you, but see comment above:

MouseClick("left", 226, 343, 2)

ControlClick returns a value, you can check it during debug:

ControlClick("Vjamm 3", "", "[CLASS:TVJammTransTab; TEXT:Patches]")

$ret = ControlClick("Vjamm 3", "", "[CLASS:TVJammTransTab; TEXT:Patches]")

MsgBox(0, "", $ret)

...or use a ConsoleWrite and run the script from within SciTE.

It is best not to rely on Sleep lines - but sometimes you have too:

Sleep(300)

maybe a ControlCommand checking for "IsEnabled" as in

Do

Sleep(100)

Until ControlCommand.......

A ControlClick or ControlFocus/ControlSend might do better here:

MouseClick("left", 154, 469, 4)

Maybe a WinWait with some unique text instead:

Sleep(2000)

A ControlClick or ControlFocus/ControlSend might do better here:

MouseClick("left", 782, 611, 1)

Maybe a WinWait with some unique text instead:

Sleep(1000)

A ControlClick or ControlFocus/ControlSend might do better here:

Send("{Tab}")

...hope this helps...

Just remember that I don't always get things right, hence my custom title of Most Senile Poster (MSP).

-MSP-

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