Question

I am writing an AutoHotkey script in which I need to handle control events. To be more specific, I have an Edit and a buddy UpDown control. I need to respond/handle the event when user press Enter within the Edit or as another example need to respond to the changes caused by up/down control (doesn't matter user goes for arrow keys to up/down the Edit value or clicks those small up/down buttons).

Please give me a clue on how to handle control events especially about Edit and UpDown controls.

Was it helpful?

Solution

Edit control documentation :
http://ahkscript.org/docs/commands/GuiControls.htm#Edit

UpDown control documentation :
http://ahkscript.org/docs/commands/GuiControls.htm#UpDown

OnMessage() function documentation :
http://ahkscript.org/docs/commands/OnMessage.htm

Example Implementation :

Gui, Add, Edit, gEventHandler vMyEditControl
Gui, Add, UpDown, vMyUpDown Range1-10, 5
Gui, Show
OnMessage(WM_KEYUP:=0x101,"WM_KEYUP") ; WM_KEYUP msg, see http://msdn.microsoft.com/library/ms646281
return

GuiClose: ; exit app on 'guiclose' event
ExitApp

EventHandler: ; This label is launched when the contents of the edit has changed
    GuiControlGet,value,,MyEditControl
    MsgBox MyEditControl contains "%value%".
return

WM_KEYUP(wParam, lParam) { ; this function is launched on 'Key Up' event
    if (wParam==0x0D) ; vk codes, see http://msdn.microsoft.com/library/dd375731
        MsgBox Enter was pressed in MyEditControl.
}

OTHER TIPS

OR, if you have multiple Edit controls on the window and you want to handle the Enter press for particular Edit controls then improve by this :

WM_KEYUP(wParam, lParam) 
{ 
    ; vk codes, see http://msdn.microsoft.com/library/dd375731
    IF (wParam==0x0D) ; 'Key Up' event for 'Enter'  
    {
        GuiControlGet, FocusCtrl, FocusV
        IF (FocusCtrl="MyEditControl") ; Focus is on MyEditControl Edit control
        {
            ; when Enter is pressed and when MyEditControl has the keyboard focus
            MsgBox Enter Presses on MyEditControl   
        }
    }    
}

Especial thanks to Joe DF for his helpful answer and nice documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top