AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Alternative to ImageSearch for controlling an app's state
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 05, 2009 4:33 pm    Post subject: Alternative to ImageSearch for controlling an app's state Reply with quote

[edited the thread's title to better reflect the current discussion topic]

Hi forum,

a standard script of mine (always running in the background) does an ImageSearch every certain fraction of a second.

The ImageSearch however unfortunately conflicts with one application (PDF-XChange Viewer) in that it closes the application's menus every time....... Sad

This means I can't use any menus of PDF-XChange Viewer when at the same time my standard script is running (which is supposed to run all the time).

Any thoughts on what could cause this strange conflict, and what possibly could be done about it?

Thanks heaps already
David.P


Last edited by David.P on Fri Nov 20, 2009 5:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 05, 2009 4:39 pm    Post subject: Reply with quote

oh well..... Embarassed

Just added the line
Code:
IfWinNotActive,  - PDF-XChange Viewer

before that ImageSearch command.......

Still... it would be interesting to know what causes this conflict.

Cheers David.P
Back to top
View user's profile Send private message
Ace Coder



Joined: 26 Oct 2009
Posts: 361

PostPosted: Thu Nov 05, 2009 4:56 pm    Post subject: Reply with quote

What is the image search for? Maybe theres another way better than image search.
Back to top
View user's profile Send private message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 05, 2009 5:03 pm    Post subject: Reply with quote

Yeah, I wish there WERE another (reasonable) way than ImageSearch to do this.
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Thu Nov 05, 2009 7:48 pm    Post subject: Reply with quote

David.P wrote:
Still... it would be interesting to know what causes this conflict.

The thread you reference was in August.
Post your code. Maybe we can find the conflict.
Back to top
View user's profile Send private message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 05, 2009 9:31 pm    Post subject: Reply with quote

Well... here's the code:

Code:
;###########################
; Search where the Tray Icon of NaturallySpeaking is placed,
; watch the microphone on/off state and react if it is in the wrong state
;###########################

MicImageSearch:
WinGetPos, trayX, trayY, trayWidth, trayHeight, ahk_class Shell_TrayWnd ; get tray area size & position
{
ImageSearch, MicIconX, MicIconY, trayX, trayY, trayX+trayWidth, trayY+trayHeight , *66 MicOff.png ; look for the red Mic Off icon in the task tray
If ErrorLevel = 0 ; if MicOff symbol is found but mic should be on, switch it on
{
IfEqual, Color, Green ; Var "Green" means that mic should be on
Send, {F9} ;switch the mic on
}
else
{
ImageSearch, MicIconX, MicIconY, trayX, trayY, trayX+trayWidth, trayY+trayHeight , *66 MicOn.png  ; look for the green Mic On icon
If ErrorLevel = 0 ; if MicOn symbol is found but mic should be off, switch it off
IfEqual, Color, Red ; Var "Red" means that mic should be off
Send, {F10}  ; switch the mic off
}
}
Return


No idea here for another way to detect that microphone state other than doing the ImageSearch (which ImageSearch then conflicts with the menus of PDF XChange Viewer).

David.P
Back to top
View user's profile Send private message
Ace Coder



Joined: 26 Oct 2009
Posts: 361

PostPosted: Thu Nov 05, 2009 10:53 pm    Post subject: Reply with quote

Off the top of my head... With no REAL thought... OnMessage ControlGet. 9 times out of 10 there is a MUCH better method than imagesearch that will be faster use less CPU and be fun to learn. Good luck
Back to top
View user's profile Send private message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 19, 2009 2:30 pm    Post subject: Are these window messages of any use? Reply with quote

Hi Ace and sorry that it took me such a long time to reply.

Thank you for sharing your ideas.

Below is what I could spy from the respective app's window, when the "mic on" or "mic off" keystrokes, respectively, are sent to that window:



Do you think these messages could be used to find out whether that microphone symbol is green or red....?




Thanks heaps already,
Cheers David.P
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Thu Nov 19, 2009 3:50 pm    Post subject: Reply with quote

is the info shown by autoit window spy the same between the two states?

out of curiosity, why do you need to detect the state?
perhaps when you want it to be on, you can send the message to turn it on. If it's already on, it might not have a problem with that.

PixelGetColor? Hopefully won't interfere with the menus in the other program.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 19, 2009 4:01 pm    Post subject: Reply with quote

engunneer wrote:
is the info shown by autoit window spy the same between the two states?

I can't seem to find anything of the above messages with the AHK window spy... I thought the AHK window spy only shows window text and class names?

The reason for the need to find the mic state is that

a) the keystroke for "mic on" and "mic off" is the bloody same keystroke in that application, so I'm never quite sure about the state of that mic, and

b) the mic state on some occasions changes by itself, so the script should be notified and react accordingly....

Cheers David.P
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Thu Nov 19, 2009 4:03 pm    Post subject: Reply with quote

David.P wrote:

I can't seem to find anything of the above messages with the AHK window spy... I thought the AHK window spy only shows window text and class names?


It does, but perhaps the statusbar text gives a clue?

Does PixelGetColor interfere with your other program?
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 19, 2009 4:13 pm    Post subject: Reply with quote

engunneer wrote:
perhaps the statusbar text gives a clue?

Yes, that could be another way. But I'd rather catch those mic on/off messages directly (or something) in order not having to look for the statusbar text every few hundred milliseconds.

engunneer wrote:
Does PixelGetColor interfere with your other program?

This would be another possibility, but has the same drawback as above (having to watch that pixel color all the time).

Basically I'm looking for a way to check OR to control that microphone state DIRECTLY......

If only that application had DIFFERENT hotkeys for "mic on" and "mic off"....
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Thu Nov 19, 2009 4:16 pm    Post subject: Reply with quote

does it have menu items instead of a hotkey that are different?

WinMenuSelectItem might do it.

Checking the statusbar constantly should not have issues for speed/performance
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 19, 2009 4:27 pm    Post subject: Reply with quote

Aaaaaaaaaaaaahhh could this be it???????





This should work without confusing the on and off states, shouldn't it.......???? Shocked Shocked Shocked

Or does WinMenuSelectItem actually OPEN the menu (visibly)?
Back to top
View user's profile Send private message
David.P



Joined: 18 Nov 2006
Posts: 304

PostPosted: Thu Nov 19, 2009 7:49 pm    Post subject: Reply with quote

Arghh that Dragon application has nonstandard menus which don't react on "WinMenuSelectItem".....!

And "PostMessage" is not applicable either, since it is the SAME stupid wm_command message for "mic on" and "mic off"....!

So is there any way that I can use this "wParam: 0x96012174, HDC: 0x96012174" stuff for "mic on" and "mic off" that Winspector gives me (see above table) -- maybe with OnMessage()...?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group