Solved - Control Send to a specific Word Window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mario_germany
Posts: 8
Joined: 28 Mar 2016, 04:54

Solved - Control Send to a specific Word Window

12 Feb 2018, 13:45

Hello from Germany (an sorry for my bad english) :oops:

thanks a lot for your Help in this forum an all the other online informations about AHK …but also I searched a lot online and in this forum I can‘t find the answer for my problem.

I want to send a text (Textdummy) to a specific Microsoft-Word (not active) window in the background.

The following code works fine, but sends the text always to the last word window that was open:
ControlSend, _WwG1, Textdummy, ahk_class OpusApp

After studying the online resources I thought the following code – line should work:
ControlSend, _WwG1, Textdummy, Testfile - Microsoft Word
but it do not?

>>>>>>>> Whats wrong?


Here is the result of the window – spy – tool the target Word-Window shows ****************************

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Testfile - Microsoft Word
ahk_class OpusApp

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 2060, 305 (less often used)
In Active Window: 144, 309

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: _WwG1
Text: Microsoft Word-Dokument
Color: 0xC8D0D4 (Blue=C8 Green=D0 Red=D4)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 1916 top: -4 width: 1032 height: 1288

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
MsoDockTop
Ribbon
Ribbon
MsoDockBottom
Statusleiste
Statusleiste
Testfile
MSO Generic Control Container
MSO Generic Control Container
Microsoft Word-Dokument
Vertikal

**************************************************************************************************

Greatings from Mario (Germany)
Last edited by mario_germany on 20 Feb 2018, 03:01, edited 1 time in total.
User avatar
boiler
Posts: 16932
Joined: 21 Dec 2014, 02:44

Re: Control Send to a specific Word Window

12 Feb 2018, 15:28

It may just be that Word will not respond to keys sent to it when it is not the active window. ControlSend doesn't work in all situations.
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Control Send to a specific Word Window

12 Feb 2018, 15:57

mario_germany, you could try this:

Code: Select all

InsertTextIntoWord("Textdummy", "Testfile")

InsertTextIntoWord(text, title)  {
   if !oWord := GetWord(title)  {
      MsgBox, Failed to get Word Application object!
      Return
   }
   sel := oWord.Selection
   sel.Text := text
   sel.Collapse(wdCollapseEnd := 0)
}

GetWord(title)  {
   ControlGet, ControlHwnd, Hwnd,, _WwG1, % title
   Return AccObjectFromWindow(ControlHwnd, -16).Application
}

AccObjectFromWindow(hWnd, idObject = 0)
{
   static IID_IDispatch   := "{00020400-0000-0000-C000-000000000046}"
        , IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
        , OBJID_NATIVEOM  := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
        , h := DllCall("LoadLibrary", Str, "oleacc", Ptr)
        
   VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
   DllCall("ole32\CLSIDFromString", Str, idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, Ptr, &IID)
   if DllCall("oleacc\AccessibleObjectFromWindow", Ptr, hWnd, UInt, idObject, Ptr, &IID, PtrP, pAcc) = 0
      Return ComObjEnwrap(VT_DISPATCH, pAcc, F_OWNVALUE)
}
Last edited by teadrinker on 12 Feb 2018, 16:06, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Control Send to a specific Word Window

12 Feb 2018, 16:04

I got a script to work. Cheers.

Code: Select all

q:: ;send text to MS Word (inactive window)
;if Word is inactive: sends to Word without activating window
;if Word is active (a Word window, not the one we want to send text to): sends to Word and activates window
ControlFocus, _WwG1, Document1 ahk_class OpusApp
ControlSend, _WwG1, abcde, Document1 ahk_class OpusApp
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Control Send to a specific Word Window

12 Feb 2018, 16:17

jeeswg wrote:I got a script to work. Cheers.
Hi, jeeswg
This works, but not if the Word window is minimized.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Control Send to a specific Word Window

12 Feb 2018, 16:25

- Yes, you're the right, I've just tested, the window must be in the normal state, not minimised, but can be underneath windows or off the screen.
- With things like sending to inactive windows, the behaviour can be a bit unpredictable, it depends on the application.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
mario_germany
Posts: 8
Joined: 28 Mar 2016, 04:54

Re: Control Send to a specific Word Window

20 Feb 2018, 03:00

Thanks a lot! I took jeeswgs Option! TNANKS

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333 and 370 guests