Jump to content

Handle keyboard Input in and Input Box


Aiakonai
 Share

Recommended Posts

Hello,

I am trying to create an input box that when a user types something like the character "." that it will prevent that character from entering the input box and display a message 

stating why the input was prevented. Something like what $ES_NUMBER style does for the input box, but for a floating point number. I can work out the logic of how to do that, but

I am not yet sure how to correctly capture keyboard input before it arrives IN the input box. This should only run on the particular input box in question as it is an aid to help clean 

up user input before it gets sent to a SQL query.

 

I was hoping for something like:

 

$msg = GUIGetMsg()
 
 Switch $msg
    Case $keyboardInput
       ; pre processing function called here

I have searched for something similar to this but I cannot seem to find one that does exactly what I am looking for. Any help is appreciated.

 

Thanks,

K

hmm... I wonder which key is the any key :O

Link to comment
Share on other sites

try this

 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 177, 82, 192, 124)
Global $Input1 = GUICtrlCreateInput("Input1", 16, 24, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg(0x0111, "_WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $WParam, $LParam)
    #forceref $hWnd, $iMsg
    Local $iCode = BitShift($WParam, 16)
    Switch $hWnd
        Case $Form1
            Switch $LParam
                Case GUICtrlGetHandle($Input1)
                    Switch $iCode
                        Case $EN_CHANGE
                            $ri = GUICtrlRead($Input1)
                            If StringInStr($ri, ",") Then
                                GUICtrlSetData($Input1, StringReplace($ri, ",", ""))
                                ToolTip("illegal character!!!")
                            EndIf
                    EndSwitch
            EndSwitch
    EndSwitch
    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

×
×
  • Create New...