Jump to content

How to activate a window and preserve text highlighting?


Recommended Posts

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.

 

Link to comment
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)
Link to comment
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.

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