Sign in to follow this  
Followers 0
Rozek

how to intercept keystrokes

4 posts in this topic

Hello!

I'm quite new to AutoIt, thus, please excuse me if the following question is too trivial - but I could not find an answer by searching this forum.

Is there any way to intercept certain keystrokes on their way to the control which currently owns the focus? I'm thinking of a (multi-line) edit control which I would like to tailor by providing formatting functions which run while the user is adding some text.

To my current understanding, I can only "read" the final text, but not "observe" what the user is entering - is that correct?

Thanks in advance for any help!

Kind regards,

Andreas Rozek

Share this post


Link to post
Share on other sites



Hello!

I'm quite new to AutoIt, thus, please excuse me if the following question is too trivial - but I could not find an answer by searching this forum.

Is there any way to intercept certain keystrokes on their way to the control which currently owns the focus? I'm thinking of a (multi-line) edit control which I would like to tailor by providing formatting functions which run while the user is adding some text.

To my current understanding, I can only "read" the final text, but not "observe" what the user is entering - is that correct?

Thanks in advance for any help!

Kind regards,

Andreas Rozek

Welcome to the forums Andreas!

There are a few ways to do what you want, probably the best being this lifted from gasfrost's version for detecting changes in a combo box ( http://www.autoitscript.com/forum/index.ph...st&p=357491 )

;original code by gafrost
;http://www.autoitscript.com/forum/index.php?s=&showtopic=47709&view=findpost&p=357491
;
#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE =0x0300
Global Const $EN_UPDATE =0x0400
Global Const $DebugIt = 1

GUICreate("My GUI combo")  ; will create a dialog box that when displayed is centered

$edit = GUICtrlCreateEdit("", 10,10,300,100) ; create first item
;GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default
$btn = GUICtrlCreateButton("Ok", 40, 120, 60, 20)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            ExitLoop
    EndSelect
WEnd

Func _Edit_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then 
        TrayTip("Edit Changed:", GUICtrlRead($Edit),1)
        _DebugPrint("Edit Changed:" & GUICtrlRead($Edit))
    EndIf
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Combo_Changed

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam
   
    Switch $nID
        Case $edit
            Switch $nNotifyCode
                Case $EN_UPDATE, $EN_CHANGE ; when user types in new data
                    _Edit_Changed()
                
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_Text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_Text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint



Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

You might also find CyberSlug's data validation procedure worth a look http://www.autoitscript.com/forum/index.ph...st&p=354577

Share this post


Link to post
Share on other sites

Incredible!

I'm always surprised how much one can achieve with AutoIt (compared to "full-blown programming languages").

Thanks for your answer, "res nullius" (did you intentionally choose that nick? I had latin at school and know the meaning...)

Now I just have to find the proper constant values.

Kind regards,

Andreas Rozek

Share this post


Link to post
Share on other sites

Incredible!

I'm always surprised how much one can achieve with AutoIt (compared to "full-blown programming languages").

Thanks for your answer, "res nullius" (did you intentionally choose that nick? I had latin at school and know the meaning...)

Now I just have to find the proper constant values.

Kind regards,

Andreas Rozek

Yes, the nick was chosen with purpose, as regards the strictest definition and not the latter portion of the legal definition. Ididn't take Latin at school but have a fondness for interesting words and phrases in it (and many other languages). For instance: "Asinus asinum fricat" is one of my favorites...

What constant values are you looking for?

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