Can't get AHK to seem to register change of window in SAP

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maxxev
Posts: 2
Joined: 08 Dec 2021, 04:40

Can't get AHK to seem to register change of window in SAP

08 Dec 2021, 04:50

Total beginner, First code.

Trying to automate a usage decision temporarily due to staff shortages

My code works but I've had to use timing rather than WaitWinActive as despite the fact if I capture the active window and return it in a message box with WinExist("A") AHK doesn't seem to register that. I also can't use the loop as I can't break it, so at the moment it goes on endlessly, I tried using an input box and times but there are other reasons why I need to be able to break the code as if another users is in the inspection it causes a nightmare.

Code: Select all

#Warn all
global Break_Window:= 0x20400

^j::

Loop
{

;Enters UD code and saves the UD
send, ZU02
send, {Ctrl down}s{Ctrl up}
Sleep, 500 ;Required as cant get WinWaitActive to work)

;Activates the pop up window and tabs left once, presses enter
ActiveWin := WinExist("A") 
;msgbox %ActiveWinB% ;(returned 0xf03ae)
WinActivate "ahk_id %ActiveWin%"
send, {lshift down}{tab}{lshift up}
send, {Enter}	
Sleep, 1000 ;Required as cant get WinWaitActive to work)

;NOT WORKING - This code is meant to test if SAP has returned to the main inspection window (QA32) and breaks the loop if so.
ActiveWinC := WinExist("A") 
;msgbox %ActiveWinC% ;(returned 0x20400 when on QA32 window)
Ifwinactive "ahk_id" %Break_Window%
{
break
}

;'This code returns to UD window and presses tab twice to return to UD field
Sleep, 8000 ;Required as cant get WinWaitActive to work)
ActiveWinB := WinExist("A") 
;msgbox %ActiveWinB% ;(returned 0xa084c)
WinActivate "ahk_id %ActiveWinB%"
send, {Tab}		
send, {Tab}

;End loop
}

return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: Can't get AHK to seem to register change of window in SAP

08 Dec 2021, 06:54

Version 1.x uses literal strings in commands.

Code: Select all

WinActivate, ahk_id %ActiveWin%
More
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Can't get AHK to seem to register change of window in SAP

08 Dec 2021, 10:23

Also, in your code, you mention the value of the ahk_id (hWnd) captured for windows at various times. You may know this, but that number changes every time a window is created. It is not a certain value that would be the same for a particular window each time it is generated, so it shouldn’t be hard-coded into your script like this line:

Code: Select all

global Break_Window:= 0x20400
maxxev
Posts: 2
Joined: 08 Dec 2021, 04:40

Re: Can't get AHK to seem to register change of window in SAP

08 Dec 2021, 12:05

boiler wrote:
08 Dec 2021, 10:23
Also, in your code, you mention the value of the ahk_id (hWnd) captured for windows at various times. You may know this, but that number changes every time a window is created. It is not a certain value that would be the same for a particular window each time it is generated, so it shouldn’t be hard-coded into your script like this line:

Code: Select all

global Break_Window:= 0x20400
Hi, no I had no idea, is there some value that can be captured, perhaps by WinSpy that I can use to test if a particular window is open? (and what is the AHK_ beginning if there is please), I am a total beginner to this (only used VBA before) so assume I know nothing...

best regards
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Can't get AHK to seem to register change of window in SAP

08 Dec 2021, 13:54

Yes, there are several ways to determine if a particular window is open using WinExist(). You can use the expected title of the window, the process name, which you would precede with ahk_exe, and other methods as described in the description of the WinTitle parameter (all of which are captured by the Window Spy tool). Try it out and ask if you get stuck.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat and 124 guests