Problems with target window losing focus

Get help with using AutoHotkey and its commands and hotkeys
Gabby
Posts: 28
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

;*** This function is used for replacing WAP [Blank] cells with nulls (by deleting them).
; It processes up to 3000 cells, tabbing to the next. If it finds "X!x" in a cell it
; it then stops. Note that when the [Blank] cells are copied, they return a null string,
; so there's no difference between them and otherwise blank cells.
Do_Deblank:
  loop 3000
    {
    Cclip := Copy_clip()                ; do a ^C and get clipboard text.
    if (Cclip = "X!x")                    ; Termination delimeter
      {
      send {Del}
      EXIT
      }
    if Cclip =
      {
      send {Del}
      }
   send {Tab}
    }
  EXIT
User avatar
divanebaba
Posts: 744
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Problems with target window losing focus

19 Mar 2018, 23:31

Code: Select all

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 - süper advanced technology - priceless inexpensive, space-saving, energy efficient - Patent priority for sale.
Gabby
Posts: 28
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

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: 744
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

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 - süper advanced technology - priceless inexpensive, space-saving, energy efficient - Patent priority for sale.
Gabby
Posts: 28
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: Cashino, CyL0N, Google [Bot], hoppfrosch, hymal7, saeed1009, sinbad, wise_mike and 34 guests