Cotino

Lose control focus on click

9 posts in this topic

#1 ·  Posted (edited)

Hi,

The title is confusing, so here's what i want :

When I click on the GUI window, outside of any control so just the window, remove focus on any control who has it.
So if i click on an input and select the text, then click outside of the input, the input loses focus and doesnt select the text anymore.

Is there a way to do that ?

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GUImain = GUICreate("", 150, 50)
    GUISetOnEvent($GUI_EVENT_CLOSE, "EndGUI")

Global $input = GUICtrlCreateInput("Something", 5, 5, 140, 20)

GUISetState()

While 1
    Sleep(100)
WEnd

Func EndGUI()
    Exit
EndFunc

 

Edited by Cotino

Share this post


Link to post
Share on other sites



#2 ·  Posted

Cotino,

Not too difficult:

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

Global $GUImain = GUICreate("", 150, 50)
    GUISetOnEvent($GUI_EVENT_CLOSE, "EndGUI")
    GUISetOnEvent($GUI_EVENT_PRIMARYUP, "Click")

Global $input = GUICtrlCreateInput("Something", 5, 5, 140, 20)

GUISetState()

While 1
    Sleep(100)
WEnd

Func EndGUI()
    Exit
EndFunc

Func Click()
    ; Check which control in under the cursor
    $aInfo = GUIGetCursorInfo($GUImain)
    If $aInfo[4] <> $input Then
        ; If it is not the input then clear the input selection
        _GUICtrlEdit_SetSel($input, -1, -1)
    EndIf

EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Great answer as always Melba.

Thanks !

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Uhm, is there a way to not have to test if $aInfo[4] is different than every control ?

I kinda have 67 controls on my current GUI and they are not in an array.

Edited by Cotino

Share this post


Link to post
Share on other sites

#5 ·  Posted

Cotino,

Try changing the condition to this:

If $aInfo[4] = 0 Then

Now it should work whenever you are not over any of your numerous controls - if you are then they should take focus anyway.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Perfect.

One last thing though, if i start clicking inside the input to select text, and release click outside of the input, it removes focus on the input.

Any way to avoid that ?

Share this post


Link to post
Share on other sites

#7 ·  Posted

Cotino,

Try changing  GUISetOnEvent($GUI_EVENT_PRIMARYUP, "Click") to $GUI_EVENT_PRIMARYDOWN.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

Exactly what i was looking for.

Thanks again.

Share this post


Link to post
Share on other sites

#9 ·  Posted

Cotino,

Glad I could help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now