Sorry, I think that this might be a really basic question. I'm trying to move a button on a window by using a hotkey. This is the simple code that I have so far:
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.
SetTitleMatchMode, 2 ;this allows comparison of substrings of Window Titles, rather than the full text.
#SingleInstance force ; This suppresses the warning dialogue that a newly launched script is already running.
;Set up the window and add a simple button.
Gui, New, , MyGui Title
Gui, Add, Text, w500 h200, test
Gui, Color, Green
Gui, Add, Button, x250, OKButton
Gui, Show
;Now use GuiControlGet to return the position of the button:
;OPTION 1: This returns the Pos results.
GuiControlGet, T, Pos, OKButton
msgbox, Error = %Errorlevel% `nButton x = %Tx%`nButton y = %Ty%
ExitApp
;OPTION 2: This is the same as above, but in a hotkey. But now the Pos variables are empty!
Left::
GuiControlGet, T, Pos, OKButton
msgbox, Error = %Errorlevel% `nButton x = %Tx%`nButton y = %Ty%
Return
GuiEscape:
GuiClose:
ExitApp
Once I can return the position of the button via option 2, I can then add to the position a fixed amount by using GuiControl, Move, OKButton, % "x"OKButtonx+10.
So my question is, why option 1 returns the position, but that option 2 does not.
I'm sure that I'm missing something basic here - so any pointers very much appreciated.