Sign in to follow this  
Followers 0
qwert

How to activate a window and preserve text highlighting?

6 posts in this topic

I have the $hWnd of the window that was active when my script gained focus.  Now I need to reactivate that window and fetch any text that was highlighted.

The problem is that every activation command I've tried deselects the highlighted text in the other window.  Yet, if I manually click on the taskbar entry, the window activates with the text still highlighted.  I've tried various combinations of WinActivate($otherTask) ... WinSetState($otherTask, "", @SW_SHOW) ... _WinAPI_SetFocus ($otherTask) ... and even just disabling my own script with WinSetState($thisTask, "", @SW_DISABLE)
 

Nothing has worked ... and I've read 7 years of posts looking for a way.

Is there a way to emulate a taskbar selection?

Thanks in advance for any help.

 

Share this post


Link to post
Share on other sites



What about _WinAPI_SwitchToThisWindow?

Share this post


Link to post
Share on other sites

This example works for me even when the highlighted text is in a minimized window.

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

; Note:-  Before running this script from the SciTE window, highlight some text in the "AutoIt Help" window to be copied.

ClipPut("") ; Empty clipboard

WinActivate("AutoIt Help")
WinWaitActive("AutoIt Help")
Send("^c") ; Copy highlighted text in active window to clipboard.

; -------- Display clipboard ---------
WinActivate(ControlGetHandle("[Class:SciTEWindow]", "", "Scintilla2"))

Send("^v")
Send("{ENTER}")

;or

ConsoleWrite(ClipGet() & @LF)

Share this post


Link to post
Share on other sites

Thanks for the responses.

After several changes, _WinAPI_SwitchToThisWindow seems to work best in the particular script I'm working with (sending character strings window-to-window).

The new issue I'm facing is how to maintain focus on the target window during a series of Send operations.  There seems to be a timing window where focus is momentarily back on my script's GUI, such that the next Send fails.

Share this post


Link to post
Share on other sites

Is there a reason why you can't use ControlSend?

Share this post


Link to post
Share on other sites

My understanding is that ControlSend requires knowledge of the controls in the target window ... which I don't have.  An example would be sending text to cells in a spreadsheet.

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  
Followers 0