Iraj Posted December 4, 2022 Posted December 4, 2022 Hello everybody Greetings! I am checking in the script below to see if the user has input a specific term (such CAT/cat) in a window (Notepad) #include <Misc.au3> If WinActivate("Untitled - Notepad") Then While 1 If _IsPressed("43") And _IsPressed("41") And _IsPressed("54") Then ConsoleWrite("CAT is typed" & @LF) EndIf Sleep(250) WEnd EndIf The only problem is that it will only highlight CAT written in one sitting, not CAT written over time. If the user takes the time to type CAT, it needs to be highlighted that cat was entered after they type C-A-T at T. This is a project for a playground for kids. I'm constructing for the students. Any alternative approach is welcome. Thanks!
Solution Nine Posted December 4, 2022 Solution Posted December 4, 2022 (edited) Maybe this would make it more robust : #include <Constants.au3> Global Const $aWord = ["Cat", "Dog", "Bird"] HotKeySet("{ESC}", _Exit) Local $hWnd = WinGetHandle("[CLASS:Notepad]") If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Please start Notepad") Local $hEdit = ControlGetHandle($hWnd, "", "Edit1") If Not $hEdit Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Control not found") Local $sText, $sPrev Do $sText = ControlGetText($hWnd, "", $hEdit) If $sText <> $sPrev Then For $i = 0 to UBound($aWord) - 1 If StringRight($sText, StringLen($aWord[$i])) = $aWord[$i] Then ConsoleWrite($aWord[$i] & " was typed" & @CRLF) ExitLoop EndIf Next $sPrev = $sText EndIf Sleep(100) Until Not WinExists($hWnd) Func _Exit() Exit EndFunc Edited December 4, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Iraj Posted December 5, 2022 Author Posted December 5, 2022 15 hours ago, Nine said: Maybe this would make it more robust : #include <Constants.au3> Global Const $aWord = ["Cat", "Dog", "Bird"] HotKeySet("{ESC}", _Exit) Local $hWnd = WinGetHandle("[CLASS:Notepad]") If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Please start Notepad") Local $hEdit = ControlGetHandle($hWnd, "", "Edit1") If Not $hEdit Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Control not found") Local $sText, $sPrev Do $sText = ControlGetText($hWnd, "", $hEdit) If $sText <> $sPrev Then For $i = 0 to UBound($aWord) - 1 If StringRight($sText, StringLen($aWord[$i])) = $aWord[$i] Then ConsoleWrite($aWord[$i] & " was typed" & @CRLF) ExitLoop EndIf Next $sPrev = $sText EndIf Sleep(100) Until Not WinExists($hWnd) Func _Exit() Exit EndFunc Thanks its working properly....
DonChunior Posted December 5, 2022 Posted December 5, 2022 The HotStrings UDF from @jvanegmond might also be helpful for your purposes.
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