ControlGetPos works in small script, not in longer one

Get help with using AutoHotkey and its commands and hotkeys
maxotics
Posts: 3
Joined: 05 Dec 2019, 21:05
GitHub: maxrottersman

ControlGetPos works in small script, not in longer one

05 Dec 2019, 21:58

I'm trying to automate something in Adobe Premiere. This is my first day with AHK, so please excuse the simpleton code ;)

If I run this script while the "Export" window is open, it puts the cursor where I expect

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

if WinExist("ahk_exe Adobe Premiere Pro.exe")
	WinActivate, ahk_exe Adobe Premiere Pro.exe
else
	Exit

SendInput +4 ; Adobe Premiere short cut to the program window, otherwise, export may not open
Sleep, 500

ControlFocus ,Edit19
ControlGetPos, X, Y,,,Edit19

;MsgBox ,,%X%  %Y%

MouseMove %X%, %Y%, 20
MouseMove, 0, 55, 20, R
MouseClick
However, if I do this in this script where it first opens the "Export" window, it never gets the control's coords, though it will move the cursor from the relative command

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

if WinExist("ahk_exe Adobe Premiere Pro.exe")
	WinActivate, ahk_exe Adobe Premiere Pro.exe
else
	Exit

SendInput +4 ; Adobe Premiere short cut to the program window, otherwise, export may not open
Sleep, 500
; should work doesn't 'SendInput ^M ; Ctrl+M to open Export Media window'
SendInput !F
Sleep, 500
Send e
Sleep, 500
Send e
Send {Right}
Sleep, 500
Send {Enter}
;SendInput +4 ; Adobe Premiere short cut to the program window, otherwise, export may not open
Sleep, 1000

Send, {Tab}
Sleep, 500
Send, {Tab}
Sleep, 500
Send, {Tab}
Sleep, 500
Send, {Tab}
Sleep, 500
Send, {Tab}
Sleep, 500
Send, {Tab}
Sleep, 500
; we should be there anyway now


ControlFocus ,Edit19
Sleep, 500
ControlGetPos, X, Y,,,Edit19 ; NOT WORKING IN THIS SCRIPT?  WHY?

;MsgBox ,,%X%  %Y%

MouseMove %X%, %Y%, 20
MouseMove, 0, 55, 20, R
MouseClick


rakesha002
Posts: 34
Joined: 04 Dec 2017, 00:11

Re: ControlGetPos works in small script, not in longer one

06 Dec 2019, 05:43

Hi,


Probably this will help, this is from Help file

ControlGetPos gives you the target window coordinates,
Specifying in CoordMode for mouse in auto execute section to mutually work with each other. hope this helps.

""
CoordMode
Sets coordinate mode for various commands to be relative to either the active window or the screen.

CoordMode, TargetType [, RelativeTo]SParameters
TargetType
The type of target to affect. Specify one of the following words:
ToolTip: Affects ToolTip.
Pixel: Affects PixelGetColor, PixelSearch, and ImageSearch.
Mouse: Affects MouseGetPos, Click, and MouseMove/Click/Drag.
Caret: Affects the built-in variables A_CaretX and A_CaretY.
Menu: Affects the Menu Show command when coordinates are specified for it.

RelativeTo
The area to which TargetType is to be related. Specify one of the following words (if omitted, it defaults to Screen):
Screen: Coordinates are relative to the desktop (entire screen).
Relative: Coordinates are relative to the active window.
Window [v1.1.05+]: Synonymous with Relative and recommended for clarity.
Client [v1.1.05+]: Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.

""
maxotics
Posts: 3
Joined: 05 Dec 2019, 21:05
GitHub: maxrottersman

Re: ControlGetPos works in small script, not in longer one

06 Dec 2019, 09:09

Sorry, I read the help, but I don't understand why it would work when called when the "Export" window is open and not after it was opened by AHK. In either case, the Export window is the main window. Can you give more details on what you think I'm missing?
guest3456
Posts: 3123
Joined: 09 Oct 2013, 10:31

Re: ControlGetPos works in small script, not in longer one

06 Dec 2019, 10:36

maxotics wrote:
06 Dec 2019, 09:09
Can you give more details on what you think I'm missing?
you aren't specifying anything in the WinTitle parameters of the two Control commands, which means that you rely on AHK's "Last Found Window"
add these two lines right before ControlFocus to make sure that the Last Found Window is still the correct one:

Code: Select all

WinGetTitle, lfw_title
MsgBox, %lfw_title%

rakesha002
Posts: 34
Joined: 04 Dec 2017, 00:11

Re: ControlGetPos works in small script, not in longer one

06 Dec 2019, 10:56

guest3456 is right you know,
and after that try to get the window handle in focusing control and ControlGetPos
this might work. if mouse moves to a different position than desired, use coordmode.
maxotics
Posts: 3
Joined: 05 Dec 2019, 21:05
GitHub: maxrottersman

Re: ControlGetPos works in small script, not in longer one

06 Dec 2019, 14:51

Thanks @rakesha002 and @guest3456 ! My first problem was I was overlooking the top line, "Window Title" in Window Spy. After that, I keep fiddling based on both your suggestions and finally got it working. I still believe Adobe is doing some weird stuff which is making this more difficult than it should be. Anyway, the new code after the "Export Settings" panel is open.

Code: Select all

; Weird, without a re-WinActivate premiere app I can't activate the "Export Settings"
; window which has focus.  
; When Adobe opens the Export Settings panel I guess it opens in some other hidden app?
if WinExist("ahk_exe Adobe Premiere Pro.exe")
	WinActivate, ahk_exe Adobe Premiere Pro.exe

WinActivate, "Export Settings" ; Window Title was in first line of Window Spy (which I missed)!
CoordMode, Mouse, Client	; Using client "window" coordinates for mouse movement

ControlFocus, Edit19 ; Where I want to position cursor ("Comments" TextBox)
Sleep, 500
ControlGetPos, X, Y,W,H, Edit19 ; Get its position

;MsgBox ,,%X%  %Y%

MouseMove, X, Y, 20 ; Move to coordinates of the TextBox
MouseMove, 0, 23, 20, R ; Now move down to the hyperlink next to "Output Name:"
MouseClick
Again, THANKS FOR YOUR HELP!

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, Bing [Bot], boiler, Google [Bot], pnKed, SilasDeVis and 48 guests