说到send函数,个人的一点经验。几种写入方法,写在一块了,有注释,运行一次就明白了。#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <array.au3>
$Form1 = GUICreate("Form1", 231, 128)
$Button1 = GUICtrlCreateButton("发送", 40, 24, 153, 73)
GUISetState(@SW_SHOW)
WinSetOnTop($Form1, '', 1)
If Not WinActivate('[class:Notepad]') Then
Run('notepad.exe')
WinWait('[class:Notepad]')
WinActivate('[class:Notepad]')
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_Send('ABC中华人民共和国' & Random())
EndSwitch
WEnd
Func _Send($sText)
Local $aAryWin = WinList('[REGEXPTITLE:(.+)]')
;~ _ArrayDisplay($aAryWin)
For $i = 1 To $aAryWin[0][0]
If BitAND(_WinAPI_GetWindowLong($aAryWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOPMOST) Then ContinueLoop;引用前辈们的代码,其实我也看不懂
If Not BitAND(WinGetState($aAryWin[$i][1]), 2) Then ContinueLoop;引用前辈们的代码,其实我也看不懂
WinActivate($aAryWin[$i][1]);激活窗口
Send("原字符串,与输入法相关:" & @CR & $sText &"{Enter}"&@CRLF);先发送原来的字符
$vSendStr = _SendEx($sText);转换字符串,一般有send都会涉及到输入法状态
Send("修正字符串,与输入法无关:" & @CR & $vSendStr & @CRLF);转换后的字符串与输入法无关
ControlSend("[active]", "", ControlGetFocus("[active]", ""), "与输入法无关的实际字符为:" & @LF);提示语,将实际字符串打出来看一下。
ControlSend("[active]", "", ControlGetFocus("[active]", ""), $vSendStr, 1);最后一个参数1的意思按原字符模样输出,不转换。
ControlSend("[active]", "", ControlGetFocus("[active]", ""), @CRLF & "用controlSend加快速度:" & @CR & $vSendStr & @CRLF);直接用Controlsend速度很快。
$oldText = ControlGetText("[active]", "", ControlGetFocus("[active]", ""))
;ControlSetText不会激活修改事件,也就是说,如果不做别的改动,关闭记事本甚至不会提示保存。
ControlSetText("[active]", "", ControlGetFocus("[active]", ""), $oldText & "用ControlSetText置入文本:" & @CR & $sText & @CR&"ControlSetText的缺点在于不激活修改事件,原软件不会认为你做过修改!");用了Controlsend怎么少得了ControlText呢?速度更快。
Return True
Next
EndFunc ;==>_Send
Func _SendEx($sSendStr = '');论坛大神写的函数,借用一下
Local $vSendStr = '', $aSplit, $sStr, $sOptSendKeyDelay
If $sSendStr = '' Then Return SetError(1, 0, '')
$aSplit = StringSplit($sSendStr, '')
For $i = 1 To $aSplit[0]
$sStr = $aSplit[$i]
If StringRegExp($sStr, '(?i)[\w,/\\\|~`!<>\[\]\.''":@#$%\^&*\(\)-+=]', 0) Then
$vSendStr &= '{ASC ' & Asc($sStr) & '}'
Else
$vSendStr &= $sStr
EndIf
Next
Return $vSendStr
EndFunc ;==>_SendEx
|