AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ControlGetText doesn't work after hotkey pressed

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Klaus



Joined: 12 May 2005
Posts: 205
Location: Münster, Germany

PostPosted: Mon May 26, 2008 8:16 am    Post subject: ControlGetText doesn't work after hotkey pressed Reply with quote

Hi, Community,
have a look please at my little code snippet that I isolated from a bigger application:

Code:
HotKey, !a, myLabel

Gui, Add, Edit, w100 h20 vmyEdit,10
Gui, Add, Button, gmyLabel, Add
Gui, show
return

myLabel:
ControlGetText, tmpMyEdit, Edit1
if (Errorlevel != 0)
  MsgBox, %Errorlevel%
newMyEdit := tmpMyEdit + 10
GuiControl,, Edit1, %newMyEdit%
return

There is a little gui with an edit field, initially filled with the numeric value of 10.
Pressing the button there will be added 10 to the current content of my edit field.
But using the alt-a hotkey which launches the same label like the pressed button, the ControlGetText fails and the expression "newMyEdit ..." won't work and the following GuiControl... blanks the control.

Could anyone help?
Thanks in advance,
Klaus
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Mon May 26, 2008 9:03 am    Post subject: Reply with quote

Code:
HotKey, !a, myLabel

Gui, +LastFound
Gui, Add, Edit, w100 h20 vmyEdit,10
Gui, Add, Button, gmyLabel, Add
Gui, show,,blah
return

myLabel:
ControlGetText, tmpMyEdit, Edit1,blah
if (Errorlevel != 0)
  MsgBox, %Errorlevel%
newMyEdit := tmpMyEdit + 10
GuiControl,, Edit1, %newMyEdit%
return
Back to top
Klaus



Joined: 12 May 2005
Posts: 205
Location: Münster, Germany

PostPosted: Mon May 26, 2008 9:12 am    Post subject: Reply with quote

Thank you, Guest,
that's the solution , although I do not understand the technical background.
Pressing the button, ControlTextGet works without coding the window's name,
but using the hotkey, the window's name is required?
What's the difference?
Thanks again,
Klaus
Back to top
View user's profile Send private message Send e-mail
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Mon May 26, 2008 9:17 am    Post subject: Reply with quote

No need for a hotkey if you use &
Code:
Gui, Add, Edit, w100 h20 vmyEdit,10
Gui, Add, Button, gmyLabel, &Add
Gui, show
return

myLabel:
ControlGetText, tmpMyEdit, Edit1
if (Errorlevel != 0)
  MsgBox, %Errorlevel%
newMyEdit := tmpMyEdit + 10
GuiControl,, Edit1, %newMyEdit%
return
Back to top
View user's profile Send private message
Klaus, nli
Guest





PostPosted: Mon May 26, 2008 9:21 am    Post subject: Reply with quote

Thanks, HugoV, for your hint, of course there is no need for hotkeys in my sample code, but it is only a simplified excerpt of a bigger one, where hotkeys are required very well.
Regards,
Klaus
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Mon May 26, 2008 9:53 am    Post subject: Reply with quote

The reason for that error has to do with how each new thread has its own last found window.

Using the window name, or by using a command like WinWaitActive, should restore intended function, however the thread is launched.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
klaus, nli
Guest





PostPosted: Mon May 26, 2008 10:31 am    Post subject: Reply with quote

Hi, [VxE],
thank you very much for that conclusive explanation.
I have to inspect lots of programmes now concerning that case.
Thanks a lot,
Klaus
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group