How to detect if user left the active gui control?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

How to detect if user left the active gui control?

20 Sep 2018, 17:26

Hello guys,

I am trying to find how to execute a calculation function when the user leaves the active GUI control - and didnt find solutions with Google and forums search with the keywords I used...

So, as an example - I want to use this instead of relying on hotkeys like Tab or Enter that are normally used to validate an input.
The goal is to expand the catch possibilities to validate ANYTIME the active gui control is not active anymore. This way the function to calculate new values will be called no matter what happens as soon as the control looses focus that it previously had when the user was typing values inside. But it will not do so in real time like with a gLabel only when leaving control.

Please, what would be the way to do that?

Thanks for your help in advance !
Alex
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: How to detect if user left the active gui control?

21 Sep 2018, 13:26

Code: Select all

#SingleInstance, Force
#Persistent

FocusedCtl := "" ; Initialize variable
PrevFocusedCtl := "" ; Initialize variable

Gui, Margin, 10, 10
Gui, Add, Edit, w200 r1 vEdit1
Gui, Add, Edit, w200 r1 vEdit2
Gui, Add, Edit, w200 r10 vEdit3
Gui, Show, AutoSize, Example

SetTimer, Timer1, 100
return

Timer1:
	GuiControlGet, FocusedCtl, FocusV

	If (FocusedCtl <> PrevFocusedCtl) {
		GuiControl,, Edit3, % FocusedCtl
		TrayTip,, % FocusedCtl
		ToolTip, % FocusedCtl
	}

	PrevFocusedCtl := FocusedCtl
return
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: How to detect if user left the active gui control?

21 Sep 2018, 14:06

wow cool Dewd! It was easier than I thought man! I guess settimer is similar to having a super complex OnMessage added to the script right?
Thank you so much, I'll try implementing that but as for what it seems, it will probably be perfect.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 235 guests