Sign in to follow this  
Followers 0
magace

Help me detect active input box

3 posts in this topic

Hello I have written a simple gui for work to auto print labels with DYMO.  However I have one small problem.  Currently I detect when the scanner sends the tab key to call the print function.  I was thinking if I can just detect when a input box is active or the curser is in the input box I could do away with the _ispressed function making the script run smoother.

 

Here is a sample gui showing what I would like to do please let me know if anything is unclear.

 

Thanks!

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("Print", 310, 370, 85, 25)
    Local $inp1 = GUICtrlCreateInput("Scan goes here then tabs to the next InputBox", 10, 35, 300, 20) ; will not accept drag&drop files
    Local $inp2 = GUICtrlCreateInput("I want to detect when this input box is active/curser is here", 10, 55, 300, 20) ; will not accept drag&drop files

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

test.png

Share this post


Link to post
Share on other sites



Hi magace,

It's not very elegant, it's just some snippets that i put it together to give you an ideia. Look if this helps:

#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>

Example()

Func Example()
    Local $sMsg1 = ""
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("Print", 310, 370, 85, 25)
    Local $inp1 = GUICtrlCreateInput("Scan goes here then tabs to the next InputBox", 10, 35, 300, 20) ; will not accept drag&drop files
    Local $inp2 = GUICtrlCreateInput("I want to detect when this input box is active/curser is here", 10, 55, 300, 20) ; will not accept drag&drop files

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $hWnd = ControlGetHandle(WinGetHandle("Example"), "", "[CLASSNN:Edit2]")
    Local $MouseOver = False

    ; Loop until the user exits.
    While 1
        $tPoint = _WinAPI_GetMousePos()
        If _WinAPI_WindowFromPoint($tPoint) = $hWnd Then
            If Not $MouseOver Then
                ; Do something
                ConsoleWrite('MouseOver' & @CRLF)
                $MouseOver = 1
            EndIf
        Else
            If $MouseOver Then
                ; Do something
                ConsoleWrite('MouseOver Lost' & @CRLF)
                $MouseOver = 0
            EndIf
        EndIf

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                GUIDelete()
                Exit
            Case Else
                $sFocus = ControlGetFocus($hGUI)
                $hFocus = ControlGetHandle($hGUI, "", $sFocus)
                $ctrlFocus = _WinAPI_GetDlgCtrlID($hFocus)
                $sMsg = "Focus:" & @CRLF & _
                        @TAB & "ClassNameNN = " & $sFocus & @CRLF & _
                        @TAB & "Hwnd = " & $hFocus & @CRLF & _
                        @TAB & "ID = " & $ctrlFocus
                If $sMsg <> $sMsg1 Then
                    ConsoleWrite($sMsg & @CRLF)
                    $sMsg1 = $sMsg
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Exit

 

Share this post


Link to post
Share on other sites

Thanks this helps a ton!

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
Sign in to follow this  
Followers 0