Jump to content
Sign in to follow this  
TheLandYacht

Problem with a simple script, one change kills the script.

Recommended Posts

TheLandYacht

Noob question

So I've got a simple script I've created to (quickly) send a keypress to a background application, then switch back to the application I was already in...and seems to work just fine with some keypresses, but the script fails to function at all with others.

Specifically, in line 5, the script works fine with (F2) or +(F5), but not with (F1) or (F5).

A bit about these keypresses in the application, F2 is "options" & (shift)F5 is "Sync All".  F1 is "Connect", F5 is "Sync current window".  All four keys work when pressed directly (physical keyboard).

Help?

Sleep(3000)
   ;~This gets the window title of the currently active window
    $title=WinGetTitle("[active]")
   ;~This sends a keypress or whatever you want to MPE, even if it's minimized or not in-focus.
   ControlSend( "MyPhoneExplorer", "", "", "+{F5}")
   ;~I found you needed a short delay between telling MPE to do something & switching back to your window, half a second was enough for me.
    Sleep(500)
   ;~This brings back your window
    WinActivate($title)
   ;~This stuff's specific to my application, you can ignore it.
    If WinActive("Zoom Player") Then
      ControlSend( "Zoom Player", "", "", "!t")
    EndIf

All of this because I can't figure out how to send a keypress to a background application (background, not minimized) without bringing it to the front (focus)...which was my original intent.

Share this post


Link to post
Share on other sites
TheLandYacht

You must specify the controlID parameter in the ControlSend function.

 

Hmm...thought it'd be as easy as using AI Window Info to get that (summary window has a spot for ID: under >>>Control<<<

but that field remains empty.

Class, ClassNameNN, etc come up with values..."ID:" is empty tho.

Also, the first two (F2 & shiftF5) work fine in the script...while the second two (F1 & F5) don't.  If controlID were required, wouldn't it crash & burn no matter what was keypress I used?

Is there another way to send a keypress to a window in the background other than ControlSend?

Share this post


Link to post
Share on other sites
FireFox

You must specify the controlID parameter in the ControlSend function.

Not necessarily.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
TheLandYacht

FireFox : OK, thanks. I thought it was a setting that was necessarily set. But on which control dos ControlSend will operate in this case ?

 

In this case, I'm not trying to send it to a control, but as a method of sending a keypress to the window itself...a window that is NOT currently "up front" so-to-speak.

I could have done it with 2 steps, using WinActivate followed by Send (keypress)...but that seemed inelegant...especially when the initial goal was to send a keypress WITHOUT bringing that application "up front".

 

BTW...My initial (secondary) question still stands.  Is there a way to send a keypress to an application WITHOUT bringing it "up front"?

Share this post


Link to post
Share on other sites
FireFox

BTW...My initial (secondary) question still stands.  Is there a way to send a keypress to an application WITHOUT bringing it "up front"?

Try ControlFocus with an empty control ID.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
TheLandYacht

Try ControlFocus with an empty control ID.

 

At first glance, that doesn't appear to give me the opportunity to send a keypress to the application (that's the goal)

Share this post


Link to post
Share on other sites
FireFox

But on which control dos ControlSend will operate in this case ?

It takes the window handle.

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
TheLandYacht

So...it looks like the whole problem is...the application (MyPhoneExplorer) likes certain keys (sent from AutoIt) just fine, but others it won't accept unless they're physically pressed.  I thought keyboard emulation was supposed to be "as good as the real thing"...or what's the point?

Any ideas?

Share this post


Link to post
Share on other sites
JLogan3o13

This works just fine for me on WIN7 x64, MyPhoneExplorer 1.8.5:

Local $hWnd = WinWait("MyPhoneExplorer","")
Sleep(1000)

ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F1}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F2}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F5}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "+{F5}")
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
TheLandYacht

 

This works just fine for me on WIN7 x64, MyPhoneExplorer 1.8.5:

Local $hWnd = WinWait("MyPhoneExplorer","")
Sleep(1000)

ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F1}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F2}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F5}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "+{F5}")

 

What, exactly, does $hWnd, do?

Share this post


Link to post
Share on other sites
JLogan3o13

$hWnd is a variable, which is set to the Window's handle (as FireFox tried to point out to you in post #9).


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
TheLandYacht

So...tried your function as a stand-alone script & it works as advertised. 

BUT...plugging your function (used the {F5} line) into my script in place of line five broke it.  

Removing the first couple of lines of your function and the mention of $hWnd seemed to work.  So it looks like the first response I got in the thread was (sort of) right.  It did need to be pointed at a specific ControlID?

And yes, the infinite loop is deliberate...I want this to run as long as the computer's running.

Ended up with...

While 1=1
    Sleep(2000)
    ;~This gets the window title of the currently active window
    $title=WinGetTitle("[active]")
    ;~This sends a keypress or whatever you want to MPE, even if it's minimized or not in-focus.
    ControlSend("MyPhoneExplorer", "", "[CLASS:ToolbarWindow32]", "{F5}")
    ;~I found you needed a short delay between telling MPE to do something & switching back to your window, half a second was enough for me.
    Sleep(500)
    ;~This brings back your window
    WinActivate($title)
    ;~This stuff's specific to my application, you can ignore it.
;~     If WinActive("Zoom Player") Then
;~      ControlSend( "Zoom Player", "", "", "!t")
;~     EndIf
    If WinActive("Interface") Then
        WinActivate("Zoom Player")
    EndIf
    ;~Sleep for 10 minutes
    Sleep(600000)
WEnd

 

This works just fine for me on WIN7 x64, MyPhoneExplorer 1.8.5:

Local $hWnd = WinWait("MyPhoneExplorer","")
Sleep(1000)

ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F1}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F2}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F5}")
;Or
ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "+{F5}")

Share this post


Link to post
Share on other sites
TheLandYacht

$hWnd is a variable, which is set to the Window's handle (as FireFox tried to point out to you in post #9).

 

Looks like both I and FireFox were answering a question by jguinch (my response is is #6, I just didn't have the language to put it into technical terms).

As to variables, I guess I'll have to do a bit of research on how to use them effectively in the future.

THANK YOU for your help with this!

Share this post


Link to post
Share on other sites
JLogan3o13

Once again "broke it" does not qualify as an explanation. What broke: did you get an error, did it simply not send the commands you expected, did it send the wrong command? Help us help you by providing an adequate amount of information ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
JLogan3o13

Yes, as much as you (and we have all been there) want to start coding now, if you do not understand what a variable is, and how to employ them, you need to take a step back and read through the help file. Reading the first few sections of the help file, as well as looking at the Examples in each section and the Tutorials on the Wiki, is the best thing you can do for yourself at this point.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
TheLandYacht

Once again "broke it" does not qualify as an explanation. What broke: did you get an error, did it simply not send the commands you expected, did it send the wrong command? Help us help you by providing an adequate amount of information ;)

 

Oops, to clarify...it seems not to proceed through that step.  I couldn't tell you more without some idea of how I would go about debugging it to figure out where/how it's broken.

What I do know is...while the one I pasted above works...this one (below) doesn't...for whatever reason.  How would I go about figuring out where/how it's broken?

While 1=1
    Sleep(2000)
    ;~This gets the window title of the currently active window
    $title=WinGetTitle("[active]")
    ;~This sends a keypress or whatever you want to MPE, even if it's minimized or not in-focus.
Local $hWnd = WinWait("MyPhoneExplorer","")
Sleep(1000)

ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F5}")
    ;~I found you needed a short delay between telling MPE to do something & switching back to your window, half a second was enough for me.
    Sleep(500)
    ;~This brings back your window
    WinActivate($title)
    ;~This stuff's specific to my application, you can ignore it.
;~     If WinActive("Zoom Player") Then
;~      ControlSend( "Zoom Player", "", "", "!t")
;~     EndIf
    If WinActive("Interface") Then
        WinActivate("Zoom Player")
    EndIf
    ;~Sleep for 10 minutes
    Sleep(600000)
WEnd

Share this post


Link to post
Share on other sites
TheLandYacht

Yes, as much as you (and we have all been there) want to start coding now, if you do not understand what a variable is, and how to employ them, you need to take a step back and read through the help file. Reading the first few sections of the help file, as well as looking at the Examples in each section and the Tutorials on the Wiki, is the best thing you can do for yourself at this point.

 

Believe me, I feel where you're coming from.  I didn't do this because I wanted to code.  I had something I needed to automate...and turned to this as the easiest method.

I knew in advance what I came up with would probably be dirty & inelegant.  But all I needed was something that would work consistently on my one (actually 2 identical) machine(s).

Share this post


Link to post
Share on other sites
FireFox

While <condition>
;you wrote "While 1=1", the expression "1=1" equals to 1 so better do like everyone and set 1 or eventually True

While 1
    ;...
WEnd

;how to debug?
$vRetVal = AFunc(<some args>)
$iErr = @Error

ConsoleWrite("AFunc debug, return value=" & $vRetVal & ", error code=" & $iErr & @Lf)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  

×