Jump to content

Any keydown/up detection or a better solution


Go to solution Solved by KaFu,

Recommended Posts

I want to activate a function based on any key up detection in an input, the function would enable/disable a button based on if the input is empty or not. The only way I can think of to do this INSTANTLY is put an if condition in the main while loop and I don't want to do that. Any other way would require some secondary interaction to enable/disable the button. Is there a better way to accomplish this?

Link to comment
Share on other sites

  • Solution

Register WM_COMMAND and look for the respective EN_UPDATE call.

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

Global $hGUI = GUICreate("Example")
Global $c_Input = GUICtrlCreateInput("", 10, 10, 200, 20)
Global $h_Input = GUICtrlGetHandle($c_Input)
Global $c_Button = GUICtrlCreateButton("Test", 10, 50, 200, 20)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = _WinAPI_HiWord($wParam)
    Local $iId = _WinAPI_LoWord($wParam)
    Local $hCtrl = $lParam
    
    If $hCtrl = $h_Input Then
        If $nNotifyCode = $EN_UPDATE Then ; Sent when an edit control is about to redraw itself. This notification code is sent after the control has formatted the text, but before it displays the text.
            ; https://learn.microsoft.com/en-us/windows/win32/controls/en-update
            ConsoleWrite(GUICtrlRead($c_Input) & @CRLF)
            If GUICtrlRead($c_Input) Then
                GUICtrlSetState($c_Button, $GUI_DISABLE)
            Else
                GUICtrlSetState($c_Button, $GUI_ENABLE)
            EndIf
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...