Problems with target window losing focus

Get help with using AutoHotkey and its commands and hotkeys
Gabby
Posts: 14
Joined: 19 Aug 2017, 03:55

Problems with target window losing focus

18 Mar 2018, 19:50

I'm running a function that halts as soon as the target window loses focus. I have similar functions that don't use the clipboard which work OK, ie they continue when the window loses focus.

Any suggestions?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
divanebaba
Posts: 735
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Problems with target window losing focus

19 Mar 2018, 23:31

Code: [Select all] [Download] GeSHi © Codebox Plus

SetTitleMatchMode, 1 ; must start with ...
Do_Deblank:
loop 3000
{
if !WinActive("Microsoft - Excel")
break
Cclip := Copy_clip()
....
So if your focused window is not active, the loop stops now. You just have to find the title of your window and to change choosen example in code above.

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.

ADVERTISING: Patent pending strip accumulator - advanced technology - priceless inexpensive, space-saving, energy efficient - Patent priority for sale.
Gabby
Posts: 14
Joined: 19 Aug 2017, 03:55

Re: Problems with target window losing focus

20 Mar 2018, 04:23

Okayyy. So that will let me stop the loop when the window loses the focus. I suspected that the problem was using Copy on an inactive window.

Trouble is, the window contains a grid and I've only found one way to get the cell data, which is by using Copy. GetControlText isn't returning the cell contents. So is there any way to send Copy to a window that isn't active?

I should have added my Copy_clip sub which is:

Code: [Select all] [Download] GeSHi © Codebox Plus

Copy_clip() {           ; ===================
clipboard = ;empty clipboard
Send ^C ;copy to clipboard
clipwait ;wait till something in clipboard, even blank.
CB := clipboard
return CB
}
User avatar
divanebaba
Posts: 735
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Problems with target window losing focus

20 Mar 2018, 07:22

Hi.
Are you using Excel? If yes, there are most reliable solutions with COM.
Btw: When you use clipwait inserting a little sleep is sometimes needed for stable function. Look here:

Code: [Select all] [Download] GeSHi © Codebox Plus

Copy_clip() {           ; ===================
clipboard = ;empty clipboard
Send ^c ;copy to clipboard
sleep 50 ; makes clipwait more reliable
clipwait ;wait till something in clipboard, even blank.
CB := clipboard
return CB
}

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.

ADVERTISING: Patent pending strip accumulator - advanced technology - priceless inexpensive, space-saving, energy efficient - Patent priority for sale.
Gabby
Posts: 14
Joined: 19 Aug 2017, 03:55

Re: Problems with target window losing focus

20 Mar 2018, 16:38

Thanks for that. No, not Excel - it's an app without any form of API (Excel would be easy).

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 83 guests