【问题标题】:Replicate text from AutoIt form to Notepad将文本从 AutoIt 表单复制到记事本
【发布时间】:2014-07-27 08:03:55
【问题描述】:

我正在使用此 AutoIt 代码在按下按钮时将文本发送到记事本:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form = GUICreate("Replicate text to notepad", 615, 50, 190, 122)
$Input = GUICtrlCreateInput("Placeholder text", 0, 0, 609, 21)
$Button = GUICtrlCreateButton("Send to notepad", 0, 24, 609, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Example(GUICtrlRead($Input))

    EndSwitch
WEnd

Func Example($text)

    Run("notepad.exe")

    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ControlSend($hWnd, "", "Edit1", $text)

EndFunc

效果很好。但是现在我想在按下按键后立即发送按键。 AutoIt 中有类似 OnKeyDown 的东西吗?所以我不必每次输入字符时都按发送按钮将其发送到记事本。

【问题讨论】:

标签: windows autoit notepad


【解决方案1】:

这就是我的做法。 工作非常整洁!

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Run("notepad.exe")
Global $hWnd = WinWait("[CLASS:Notepad]", "", 10)

$Form = GUICreate("Replicate text to notepad", 615, 50, 190, 122)
$Input = GUICtrlCreateInput("Placeholder text", 0, 0, 609, 21)
$Button = GUICtrlCreateButton("Send to notepad", 0, 24, 609, 25)
GUISetState(@SW_SHOW)

$OldText = ""

While 1
    $nMsg = GUIGetMsg()

    $NewText = GUICtrlRead($Input)
    If $OldText <> $NewText Then
        $OldText = $NewText
        Example($NewText)
    EndIf

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Example(GUICtrlRead($Input))

    EndSwitch
WEnd

Func Example($text)
    ControlSetText($hWnd, "", "Edit1", $text)
EndFunc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多