Jump to content

Detect Changes on Keypress


Paulie
 Share

Recommended Posts

Hey gang,

So I'm running into a problem. I'm trying to make a GUI with 5 Labels and 2 Inputboxes. 1 of the Inputs is Hidden. I want the user to enter a word, and then i want them to try to type the same word again, but I want the labels to reflect what they type except I want 1 character per label. It's hard to explain lol,

Here is a demo that explains my problem.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode",1)
Dim $Label[5]
$GUI = GUICreate("Form1", 400, 250, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
$Input = GUICtrlCreateInput("", 72, 192, 129, 21)
GUIctrlSetState(-1,$GUI_HIDE)
GUICtrlSetLimit(-1,5)
GUICtrlSetOnEvent(-1, "Compare")
For $x = 0 to 4
$Label[$x] = GUICtrlCreateLabel("", 72+40*$x, 136, 36, 17)
Next
$Compare = GUICtrlCreateInput("",200,200, 150,17)
GUICtrlSetLimit(-1,5)
GUICtrlSetOnEvent(-1, "Start")
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
    ToolTip("Enter a 5-letter word in the box and push ENTER")
WEnd
Func Start()
    ToolTip("Now that the labels work, the GUI is unresponsive"&@CRLF&"Notice, you can't close the window"&@CRLF&"And Pressing ENTER doesnt trigger OnEvent")
    While 1
        ControlFocus($GUI,"", $Input)
        $Array = StringSplit(GuiCtrlRead($Input),"")
        For $x = 0 to $Array[0]-1
            IF GUICtrlRead($Label[$x]) <> $Array[$x+1] Then
                GUICtrlSetData($Label[$x], $Array[$x+1])
            EndIf
        Next
        For $x = 0 to 4
            If $x >= UBound($Array)-1 and GUICtrlRead($Label[$x]) <> "_" then
                GUICtrlSetData($Label[$x], "_")
            EndIf
        Next
    WEnd
EndFunc
Func Quit()
    Exit
EndFunc
Func Compare()
    MsgBox(0,"", "Comparing: " &@CRLF& GuiCtrlRead(@GUI_CtrlId) &@CRLF& GuiCtrlRead($Compare))
EndFunc

Any ideas on how to make this work correctly?

Edited by Paulie
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...