Search code examples
autoit

why does not ControlSend () work, but it works great on educational tasks


I can’t understand why ControlSend () does not process in my example (Notepad ++), when it stopped showing itself in the tutorial examples (Notepad). I cannot understand what is the error and the combat error, and it does not work out ControlSend (). I work in windows 10

enter image description here

...
; увы эту строку не отрабатывает , но при это ошибку не выводит  (not wotk :( )    
;$hWnd5 =ControlSend($hWnd, "Tab", "[CLASS:SysTabControl32]", " new 1 ")
If Not $hWnd5 Then
    MsgBox(4096, 'Сообщение', 'Строчка не отработала, ControlSend, завершаем работу скрипта')
    Exit
EndIf
...

why this not work ???

all cod

; Запуск блокнота только так вызывается
Run('C:\kononov\Notepad++\notepad++.exe')

; Ожидание 5 секунд до появление окна блокнота  и проверка 
$hWnd = WinWait("[CLASS:Notepad++]", "", 5)
If Not $hWnd Then
    MsgBox(4096, 'Сообщение', 'Окно не найдено, завершаем работу скрипта')
    Exit
EndIf

;ControlClick(handle, button1);
; проверка открития 
$hWnd1  =   WinGetHandle($hWnd, "[CLASS:ToolbarWindow32; INSTANCE:1]")
If Not $hWnd1 Then
    MsgBox(4096, 'Сообщение', 'Строчка окна не найдена,WinGetHandle, завершаем работу скрипта')
    Exit
EndIf

; нажатие клавиши  и проверка , нажатие клавиши "новый "
$hWnd3  =ControlClick($hWnd, "", "[CLASS:ToolbarWindow32]", "Left", 1,11, 12)
If Not $hWnd3 Then
    MsgBox(4096, 'Сообщение', 'Строчка не отработала, ControlClick, завершаем работу скрипта')
    Exit
EndIf

; нажатие клавиши и проверка , нажатие на рабочей поверхности
$hWnd4  =ControlClick($hWnd, "", "[CLASS:SysTabControl32]", "Left", 1,550, 50)
If Not $hWnd4 Then
    MsgBox(4096, 'Сообщение', 'Строчка не отработала, ControlClick, завершаем работу скрипта')
    Exit
EndIf

; Высылает строку символов в элемент увы строуон не реализует 
$hWnd5  = ControlSend("[CLASS:Notepad++]", "Tab", "[CLASS:SysTabControl32]", "This is some text")
Send("asddas") ; вот эту срочку прекрастно отрабатывает  

 ; увы эту строку не отрабатывает , но при это ошибку не выводит     
;$hWnd5 =ControlSend($hWnd, "Tab", "[CLASS:SysTabControl32]", " new 1 ")
If Not $hWnd5 Then
    MsgBox(4096, 'Сообщение', 'Строчка не отработала, ControlSend, завершаем работу скрипта')
    Exit
EndIf

; Закрывает блокнот. ( пока открытым держим )
; WinClose($hWnd)

result

enter image description here


Solution

  • Try something like this: You can skip parameters in ControlSend like the ControlID.

    Opt('WinTitleMatchMode', 4)
    ShellExecute('notepad++.exe', '', '', '', @SW_SHOW)
    Sleep(100)
    $h = WinGetHandle("[CLASS:Notepad++]", "")
    ConsoleWrite($h & @CRLF)
    ConsoleWrite("WA " & WinActivate($h) & @crlf)
    ControlSend("[CLASS:Notepad++]", "", '', '^n')
    Sleep(200)
    ControlSend("[CLASS:Notepad++]", "", '', 'It works :-) yes')
    ;~ WinSetTitle($h, '', @UserName)