Re:How to call a function on every key press in GUI Input?
"valery_vi" <[email protected]>
| Newsgroups | gmane.comp.windows.autoit.user |
|---|---|
| Message-ID | <[email protected]> |
someone from AutoItScript wrote:
http://www.autoitscript.com/forum/index.php?showtopic=39874
>I want to make a certain function to be called on every keypress in
a >GUI Input box.
>With GUICtrlSetOnEvent it does not work. (works, but only when I hit
>Enter)
>I tryed to register the WM_KEYUP or WM_KEYDOWN message, but it does
>not work at all.
>And, YES, I want this function to be called on every key press, not
>only when I change the text in the Input and press Enter.
>Help, anyone?
I just modified script from
http://tech.groups.yahoo.com/group/AutoItList/message/30755
#include <GUIConstants.au3>
Global Const $WM_COMMAND = 0x0111
Global Const $EN_UPDATE = 0x400
Global Const $EN_SETFOCUS = 0x0100
Global $Edit, $Input
; Set up a basic test GUI
$hWnd = GUICreate("Input vs Edit", 400, 150)
$LabelOfEdit = GUICtrlCreateLabel("Edit control is fired by
{Enter},only", 10, 10, 380, 21)
$Edit = GUICtrlCreateEdit("", 10, 30, 380, 21, BitOR
($ES_WANTRETURN,$ES_AUTOVSCROLL))
$LabelOfInput = GUICtrlCreateLabel("Input control is fired by any
focus changes incl. {Tab}", 10, 50, 380, 21)
$Input = GUICtrlCreateInput("", 10, 70, 380, 21)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState()
; Start the main loop
While 1
if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
WEnd
;==================================
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $EditContent, $InputContent
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Select
Case $nID = $Edit
Select
Case $nNotifyCode = $EN_UPDATE
$EditContent = GUICtrlRead($Edit)
If StringRight($EditContent,2) = @CRLF Then
$EditContent = StringTrimRight($EditContent,2)
GUICtrlSetData($Edit,$EditContent)
WinSetTitle($hWnd, "", $EditContent)
Send("{TAB}")
EndIf
Case $nNotifyCode = $EN_SETFOCUS
;Clear content selection
Send("{RIGHT}")
EndSelect
Case $nID = $Input
$InputContent = GUICtrlRead($Input)
if $nNotifyCode = $EN_UPDATE then WinSetTitle($hWnd, "",
$InputContent)
EndSelect
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
You can see that Input update will change Window Title content.
So you can call any func instead of call of
WinSetTitle($hWnd, "", $InputContent)
Valery