Jump to content

Recommended Posts

Posted

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
Posted (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 by Nine
Posted
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....

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
×
×
  • Create New...