Jump to content
MyEarth

Get input when lose focus

Recommended Posts

MyEarth

Hello,

I want to know when an input has lose his focus. Pratically an user click on the input ( and give it the focus ) and write a word-numbers etc., when this control lose the focus ( example the user click on another input or another control ) i want to add a function for check if the data inside the control is valid, example if is empty i'll add a predefinite text or things like that. Every input has his data so i prefer to not store all the input inside an array or i'll confuse everything :D 

My fail attempt:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 275, 165, 193, 162)
$Input1 = GUICtrlCreateInput("Input1", 72, 32, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 72, 64, 121, 21)
$Input3 = GUICtrlCreateInput("Input3", 72, 96, 121, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Select
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input1)
            ConsoleWrite(1 & @CR)
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input2)
            ConsoleWrite(2 & @CR)
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input3)
            ConsoleWrite(3 & @CR)
    EndSelect
WEnd

Thanks for the help

Share this post


Link to post
Share on other sites
nitekram

Not sure if this is what you are looking for, but this one way.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 275, 165, 193, 162)
$Input1 = GUICtrlCreateInput("Input1", 72, 32, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 72, 64, 121, 21)
$Input3 = GUICtrlCreateInput("Input3", 72, 96, 121, 21)

$Value = ''
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Select
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input1)
            ; value check
            If GUICtrlRead($Input1) <> 'input1' Then
                Do
                    $Value = InputBox('enter valid value', '')
                    ;MsgBox('','','wrong input')
                    ;ConsoleWrite(1 & @CR)
                Until $Value = 'input1'
                GUICtrlSetData($Input1, $Value)
            EndIf
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input2)
            ConsoleWrite(2 & @CR)
        Case ControlGetHandle($Form1, "", ControlGetFocus($Form1)) <> GUICtrlGetHandle($Input3)
            ConsoleWrite(3 & @CR)
    EndSelect
WEnd

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
MyEarth

Thanks for the attempt but no, isn't what i'm need. i just want to know when a focused input lose his focus.

P.S. Sorry, excuse me for saying it, but that script don't have any sense. If the only valid value is "Input1" the user can't write nothing except that word so the purpose of the input dosn't exist.

Share this post


Link to post
Share on other sites
nitekram

i want to add a function for check if the data inside the control is valid,

What is the valid data?

if is empty i'll add a predefinite text or things like that. Every input has his data so i prefer to not store all the input inside an array or i'll confuse everything

 

It is going to be tough to check for valid entries if you do not have a list of those valid values - i.ei an array

If the value is not what you wanted, and you want to fill in a predifined value, if it is blank, just remove the Do/Until loop and verify the value, and if it does not meet the value, change the variable to a good value.

 

EDIT

Sorry just found an issue with my code...see my post above and retry.

Actually that did not matter...we need the values that you are looking for to continue.

Edited by nitekram
Fixed Code

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
MyEarth

You have totally miss the point of my OP. Luckily i have solved by myself usign WM_COMMAND in combination with $EN_KILLFOCUS, there is a partial example in the help, for get which control has lost the focus, the only thing i'd like to know.

I can't find the "mark as solved" or "whatever was that name" button, maybe is the new layout...

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.