`
yangzb
  • 浏览: 3473846 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

如何在web上实现对另一个应用程序的键盘输入,就像vb中的sendkey

阅读更多

set   WshShell   =   CreateObject( "WScript.Shell ")
WshShell.SendKeys   "{ESC} "

但是要提示一个安全警告,这个警告怎么去除?




这个问题原来在.com的时候也碰到过。也一直没有搞定。后来是自己写的上传组件。其实你已经如果打算用activeX,可以自己写一个File组件.如果是要上传,还可以将其写成一个FTP上传的东西,那样上传也许会更好的。
其实WScript.Shell中也有SendKeys这个方法,MSDN中用了Sleep(100),我不知道为什么,你也可以试试,这是一个例子。打开calc自己算一个东西。。
set   WshShell   =   WScript.CreateObject( "WScript.Shell ")
      WshShell.Run   "calc "
      WScript.Sleep   100
      WshShell.AppActivate   "Calculator "
      WScript.Sleep   100
      WshShell.SendKeys   "1{+} "
      WScript.Sleep   500
      WshShell.SendKeys   "2 "
      WScript.Sleep   500
      WshShell.SendKeys   "~ "
      WScript.Sleep   500
      WshShell.SendKeys   "*3 "
      WScript.Sleep   500
      WshShell.SendKeys   "~ "
      WScript.Sleep   2500

PS:取得当前的Document对象的方法是,利用ShellWindows这个对象,具体请参看MSDN中的HOWTO:   Connecting   to   a   Running   Instance   of   Internet   Explorer   ID:   Q176792,不过说实话,这种方法并不太适用。因为你得通过一些手段区分哪个是自己的窗口。
分享到:
评论
1 楼 yangzb 2011-11-16  

Delphi中支持发送中文的SendKeys(就象VB中的SendKeys一样)怎样实现?

procedure SendKeys(sSend:string);
var
    i:integer;
    focushld,windowhld:hwnd;
    threadld:dword;
    ch: byte;
begin
  windowhld:=GetForegroundWindow;
    //获得前台应用程序的活动窗口的句柄
  threadld:=GetWindowThreadProcessId(Windowhld,nil);
    //获取与指定窗口关联在一起的一个进程和线程标识符
  AttachThreadInput(GetCurrentThreadId,threadld,true);
    //通常,系统内的每个线程都有自己的输入队列。          //
    //AttachThreadInput允许线程和进程共享输入队列。        //
    //连接了线程后,输入焦点、窗口激活、鼠标捕获、键盘状态 //
    //以及输入队列状态都会进入共享状态          //
  Focushld:=getfocus;
    //获得拥有输入焦点的窗口的句柄
  AttachThreadInput(GetCurrentThreadId,threadld,false);
  if focushld = 0 then Exit;
    //如果没有输入焦点则退出发送过程
  i := 1;
  while i <= Length(sSend) do
    //该过程发送指定字符串(中英文皆可以)
  begin 
    ch := byte(sSend[ i ]);
    if Windows.IsDBCSLeadByte(ch) then
    begin
      Inc(i);
      SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend[ i ]), ch), 0);
    end
    else
      SendMessage(focushld, WM_IME_CHAR, word(ch), 0);
    Inc(i);
  end;
  postmessage(focushld,WM_keydown,13,0); 
    //发送一个虚拟Enter按键
end;

相关推荐

Global site tag (gtag.js) - Google Analytics