从AutoIt表单复制文本到记事本



我使用这个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之类的东西吗?这样我就不用每次输入一个字符都按发送键把它发送到记事本了

我是这样做的。工作很整洁!

#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

相关内容

  • 没有找到相关文章

最新更新