解决 AutoIt3 发送 unicode 字符的问题

camio

普通会员
2005-11-13
1,425
0
0
解决 AutoIt3 发送 unicode 字符的问题
AutoIt3 对于 unicode 的支持不是很好,但是可以绕道实现 Send 函数对于 unicode的支持

它的帮助文档里有这么一段话
To send UNICODE characters enter the character code, for example this sends a Chinese character
Send("{ASC 2709}")
于是我写了下面的一个小函数,测试OK

废话不多说,看代码:


Quote:代码 (双击代码复制到粘贴板);======================================================
;
; Function Name: _SendUnicode("string")
; Description: Send a unicode or an ASCII string.
; Parameter(s): $string is the string you want to send.
; Requirement(s): String Input.
; Return Value(s): None
; Author(s): Robie Zhou (robiezhou@gmail.com)
;
;======================================================
Func _SendUnicode($string)
Local $char
Local $code

For $i = 1 to StringLen($string)
$char = StringMid($string, $i, 1)
$code = Asc($char)
If $code > 127 Then
$code = $code * 256
$i = $i + 1
$char = StringMid($string, $i, 1)
$code = $code + Asc($char)
EndIf
Send("{ASC " & $code & "}")
Next
EndFunc


建议把上面的函数加到autoit安装目录下的 include 子目录的 String.au3 文件里
这样下次直接调用就可以了


再看一个例子,用上面的函数发送一个中英文混合的字符串
本例子只能运行在中文Windows上

Quote:代码 (双击代码复制到粘贴板)#include <String.au3>

Run("notepad.exe")
WinWaitActive("未定标题")
_SendUnicode("测试一下AutoIt对于Unicode的支持")
Send("{ENTER}")