C
cAkk
Unregistered / Unconfirmed
GUEST, unregistred user!
下面函数用于模拟VB里面的sendkey函数,可以向当前有焦点的输入
窗口发送中文字符串(目前不支持英文/功能建):
procedure SendKeys(Mstr:string);
var CharCode,i:integer;
Sstr:string;
focushld,windowhld:hwnd;
threadld:dword;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
Focushld:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false);
if focushld<>0 then
begin
for i:=1 to length(Mstr) do
begin
Sstr:=Mstr;
CharCode:=ord(Sstr[1]);
if length(Sstr)>1 then
CharCode:=CharCode shl 8+ord(Sstr[2]);
sendmessage(Focushld,WM_IME_CHAR,CharCode,1);
end;
end;
end;
请按我说的方法进行测试:
1.建一个新的工程,把上面函数拷贝进去;
2.放一个timer控件,在OnTimer事件里添加如下代码:
sendkeys('大富翁');
3.运行程序;
4.用鼠标切换到别的有输入焦点的程序窗口,看是否能做到每秒发送一个
'大富翁'的字符串?
注意:本程序没有考虑汉字双字节,所以鼠标不要点在一个汉字的半截部分.
否则乱麻.
测试者请报告如下:
1.操作系统环境NT/98/95/2000? 中文(废话)?
2.测试用的有输入焦点的软件? 比如:notepad,IE...等等
3.测试结果/现象.
每位参与测试者100分.(我会追加分数的)
窗口发送中文字符串(目前不支持英文/功能建):
procedure SendKeys(Mstr:string);
var CharCode,i:integer;
Sstr:string;
focushld,windowhld:hwnd;
threadld:dword;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
Focushld:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false);
if focushld<>0 then
begin
for i:=1 to length(Mstr) do
begin
Sstr:=Mstr;
CharCode:=ord(Sstr[1]);
if length(Sstr)>1 then
CharCode:=CharCode shl 8+ord(Sstr[2]);
sendmessage(Focushld,WM_IME_CHAR,CharCode,1);
end;
end;
end;
请按我说的方法进行测试:
1.建一个新的工程,把上面函数拷贝进去;
2.放一个timer控件,在OnTimer事件里添加如下代码:
sendkeys('大富翁');
3.运行程序;
4.用鼠标切换到别的有输入焦点的程序窗口,看是否能做到每秒发送一个
'大富翁'的字符串?
注意:本程序没有考虑汉字双字节,所以鼠标不要点在一个汉字的半截部分.
否则乱麻.
测试者请报告如下:
1.操作系统环境NT/98/95/2000? 中文(废话)?
2.测试用的有输入焦点的软件? 比如:notepad,IE...等等
3.测试结果/现象.
每位参与测试者100分.(我会追加分数的)