egalvez Posted August 30, 2005 Posted August 30, 2005 Hello. Let's say my dialog box displays a question:Who was the first president of the United States?and there's an edit control where the user can type in a response. I want to be able to test the user's response character-for-character while he's typing. So, if he types George, great, he can continue typing, but as soon as he gets a character wrong, the incorrect character is stripped from the edit control and no new character will appear until the correct next character is typed. So, if he types George B, the B is removed and a beep sounds and the user knows the next character must not be a B, while George W would be allowed. When I did this kind of thing using Excel VBA, it was easy. I just attached a macro to the edit control. I can't figure out how to do that in AutoIt3, however. I tried using GUICtrlSetOnEvent with an edit control, but that apparently is only for when a control is clicked, not typed in. How would I go about doing this, please?
BigDod Posted August 30, 2005 Posted August 30, 2005 You could use IsPressed but I do not know how you would code it. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
Raindancer Posted August 30, 2005 Posted August 30, 2005 (edited) Tested it with latest Beta. Seems to work. #include <guiconstants.au3> $answer = StringSplit("George W. Bush", "") $gui = GUICreate("Test", 300, 80) $Label_Question = GUICtrlCreateLabel("Who is the most idiotic President of the US of A?", 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = StringSplit(GUICtrlRead($Input_Answer),"") For $i = 1 to $useranswer[0] If Not ($useranswer[$i] = $answer[$i]) Then Beep(880, 125) GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf If $useranswer[0] = $answer[0] Then MsgBox(0,"Right", "It's George W. Bush") Exit EndIf Next WEnd #EndRegion Edit: Typo, and wrong Include Path... Edited August 30, 2005 by Raindancer Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
Moderators SmOke_N Posted August 30, 2005 Moderators Posted August 30, 2005 gafrost and Saunders were testing something like this a few days ago... You could search their names for post in the last 2 weeks... (I'd use Sauders name first... They both are Excellent... but Gary (gafrost) post like 15 post a day!! ) I'll see if I can't find it also.... GL Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
layer Posted August 30, 2005 Posted August 30, 2005 Tested it with latest Beta.Seems to work.#include <guiconstants.au3> $answer = StringSplit("George W. Bush", "") $gui = GUICreate("Test", 300, 80) $Label_Question = GUICtrlCreateLabel("Who is the most idiotic President of the US of A?", 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = StringSplit(GUICtrlRead($Input_Answer),"") For $i = 1 to $useranswer[0] If Not ($useranswer[$i] = $answer[$i]) Then Beep(880, 125) GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf If $useranswer[0] = $answer[0] Then MsgBox(0,"Right", "It's George W. Bush") Exit EndIf Next WEnd #EndRegionEdit: Typo, and wrong Include Path...<{POST_SNAPBACK}>Haha, very nice, oh so true, oh so true... FootbaG
Moderators SmOke_N Posted August 30, 2005 Moderators Posted August 30, 2005 I see there were a few post that I haven't looked at yet: But here is the link i was talking about:#102374 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
egalvez Posted August 30, 2005 Author Posted August 30, 2005 Thanks, Raindancer. It seemed to work fine, but allowed incorrect characters at the end (see screencap). I'll also check out the posts that ronsrules recommended. Thank you, folks.
GaryFrost Posted August 30, 2005 Posted August 30, 2005 I see there were a few post that I haven't looked at yet: But here is the link i was talking about:#102374<{POST_SNAPBACK}>That was the Combo autocomplete i ended up submitting to the beta. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Moderators SmOke_N Posted August 30, 2005 Moderators Posted August 30, 2005 GREAT JOB GARY!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
egalvez Posted August 30, 2005 Author Posted August 30, 2005 Since gafrost's code apparently is for comboboxes, does that mean it's not helpful in this situation. or is it a question of my modifying it to work with an edit control (if I can)? Actually, Raindancer's code may very well suffice. I only was able to break it because I was trying to, i.e., I was letting my fingers fly all over the keyboard with a rapidity that no user would ever have reason to do.
Moderators SmOke_N Posted August 30, 2005 Moderators Posted August 30, 2005 I thought you might be able to modify it... if your going to have a list of "keywords"... thought it might have helped. That way the user sees if they are typing it correctly. But if you want the answers unknown... you may not want to go down that route... GL Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Raindancer Posted August 30, 2005 Posted August 30, 2005 Thanks, Raindancer. It seemed to work fine, but allowed incorrect characters at the end (see screencap). I'll also check out the posts that ronsrules recommended. Thank you, folks.<{POST_SNAPBACK}>This Code doesn't allow wrong characters at the end of Input... try it :-)#include <guiconstants.au3> $answer = "George W. Bush" $answer_parts = StringSplit($answer, "") $gui = GUICreate("Test", 300, 80) $Label_Question = GUICtrlCreateLabel("Who is the most idiotic President of the US of A?", 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") For $i = 1 to $useranswer_parts[0] If Not ($useranswer_parts[$i] = $answer_parts[$i]) Then Beep(880, 125) GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf If $useranswer = $answer Then MsgBox(0,"Right", "It's George W. Bush") Exit EndIf Next WEnd #EndRegion Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
egalvez Posted August 30, 2005 Author Posted August 30, 2005 (edited) Thanks, Raindancer. This time it broke differently. Here's the error:Note: I'm not using a beta version of AutoIt3. So, I just commented out the Beep line in your code since that's a beta-only feature. I figure everything else should work fine, though. Edited August 30, 2005 by egalvez
Raindancer Posted August 30, 2005 Posted August 30, 2005 Thanks, Raindancer. This time it broke differently. Here's the error:Note: I'm not using a beta version of AutoIt3. So, I just commented out the Beep line in your code since that's a beta-only feature. I figure everything else should work fine, though.<{POST_SNAPBACK}>Included a length check, so the useranswer shouldn't be able to be longer then the answer.expandcollapse popup#include <guiconstants.au3> $answer = "George W. Bush" $answer_parts = StringSplit($answer, "") $gui = GUICreate("Test", 300, 80) $Label_Question = GUICtrlCreateLabel("Who is the most idiotic President of the US of A?", 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") #region *** Start of Length Check If ($useranswer_parts[0] > $answer_parts[0]) Then GUICtrlSetData($Input_Answer, StringTrimRight($useranswer, $useranswer_parts[0] - $answer_parts[0])) $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") EndIf #endregion *** End of Length Check For $i = 1 to $useranswer_parts[0] If Not ($useranswer_parts[$i] = $answer_parts[$i]) Then Beep(880, 125) GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf If $useranswer = $answer Then MsgBox(0,"Right", "It's George W. Bush") Exit EndIf Next WEnd #EndRegion Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
egalvez Posted August 30, 2005 Author Posted August 30, 2005 I got pretty much the same error this time, although no characters beyond the correct number. I'm attaching a screencap. Keep in mind I'm trying to break this, but I can't imagine that in any normal situation anyone would, so I'm not really worried about it. And I thank you for your efforts.
Raindancer Posted August 31, 2005 Posted August 31, 2005 Keep in mind I'm trying to break this... And I thank you for your efforts.<{POST_SNAPBACK}>I know. But that is real debugging. You never know whar circumstances the user creates...I'm happy to help someone to make a good script.New code... I moved the Answercheck outside of the For...Next-Loop.expandcollapse popup#include <guiconstants.au3> $title = "Quizzer" $question = "Who is the most idiotic president of the US of A?" $answer = "George W. Bush" $answer_parts = StringSplit($answer, "") $gui = GUICreate($title, 300, 80) $Label_Question = GUICtrlCreateLabel($question, 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") #region *** Start of Length Check If ($useranswer_parts[0] > $answer_parts[0]) Then GUICtrlSetData($Input_Answer, StringTrimRight($useranswer, $useranswer_parts[0] - $answer_parts[0])) $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") EndIf #endregion *** End of Length Check For $i = 1 to $useranswer_parts[0] If Not ($useranswer_parts[$i] = $answer_parts[$i]) Then Beep(880, 125) GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf Next If (GUICtrlRead($Input_Answer) = $answer) Then MsgBox(0,"Right", "It's " & $answer) Exit EndIf WEnd #EndRegion Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
egalvez Posted August 31, 2005 Author Posted August 31, 2005 It broke again, but this time I was having to type especially extremely fast and it took longer to break. It took 10-15 seconds to break it, which was longer than before. I'm attaching another screencap. Looks like the same error. Thank you.
Moderators SmOke_N Posted August 31, 2005 Moderators Posted August 31, 2005 nice code Raindancer: Try this egalvez: expandcollapse popup#include <guiconstants.au3> #include <array.au3> $title = "Quizzer" $question = "Who is the most idiotic president of the US of A?" $answer = "George W. Bush" $answer_parts = StringSplit($answer, "") $gui = GUICreate($title, 300, 80) $Label_Question = GUICtrlCreateLabel($question, 5, 5, 290, 20) $Input_Answer = GUICtrlCreateInput("", 5, 30, 290, 20) GUISetState() #Region - GUI SelectLoop While 1 $msg = GUIGetMsg() Select Case $msg = -3;$GUI_EVENT_CLOSE Exit EndSelect $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") #region *** Start of Length Check If IsArray($useranswer_parts) And IsArray($answer_parts) Then If ($useranswer_parts[0] > $answer_parts[0]) Then GUICtrlSetData($Input_Answer, StringTrimRight($useranswer, $useranswer_parts[0] - $answer_parts[0])) $useranswer = GUICtrlRead($Input_Answer) $useranswer_parts = StringSplit($useranswer,"") EndIf EndIf #endregion *** End of Length Check If IsArray($useranswer_parts) And IsArray($answer_parts) Then For $i = 1 to $useranswer_parts[0] If Not ($useranswer_parts[$i] = $answer_parts[$i]) Then GUICtrlSetData($Input_Answer, StringTrimRight(GUICtrlRead($Input_Answer), 1)) EndIf Next EndIf If (GUICtrlRead($Input_Answer) = $answer) Then MsgBox(0,"Right", "It's " & $answer) Exit EndIf WEnd #EndRegion Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Raindancer Posted August 31, 2005 Posted August 31, 2005 :"> I'm always lazy in error checking... Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
Raindancer Posted August 31, 2005 Posted August 31, 2005 This Code exploits the Quizzer code... just tries all keys until it gets the answer... WinActivate("Quizzer") Dim $array[52] = [51,"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",0,1,2,3,4,5,6,7,8,9,"ç","%","&","/","(",")","?","ü","ö","ä",",",".","$",""," "] WinWaitActive("Quizzer") While Not WinExists("Right") For $i = 1 to $array[0] Send($array[$i]) Sleep(50) If WinExists("Right") Then ExitLoop 2 Next WEnd A little slow though... Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now