刚看API没多久,想写个小东西.  比如开始运行程序,获得XX(如记事本)程序句柄,然后间隔一段时间向里面重复按一个健procedure TForm1.Button1Click(Sender: TObject);
var
  wnd: HWND;
begin
  //找到应用程序的窗口的句柄
  wnd := FindWindow(nil, '新建 文本文档.txt - 记事本');
  if wnd <> 0 then
    if isiconic(wnd) then
      ShowWindow(wnd, sw_restore)
    else
      SetForegroundWindow(wnd)
  else
    showmessage('没有找到当前窗口');
end;
这是获得记事本的代码procedure TForm1.Timer1Timer(Sender: TObject);
begin
  postmessage(edit1.Handle,wm_keydown,65,0);
end;这个另一个控件写入的代码请教,如何在记事本中实现像控件那样的功能,就是间隔一秒输入 A 

解决方案 »

  1.   

    procedure   TForm1.Timer1Timer(Sender:   TObject); 
    var 
        wnd:   HWND; 
    begin 
        //找到应用程序的窗口的句柄 
        wnd   :=   FindWindow(nil,   '新建   文本文档.txt   -   记事本'); 
        if   wnd   <>   0   then 
            if   isiconic(wnd)   then 
                ShowWindow(wnd,   sw_restore) 
            else 
                SetForegroundWindow(wnd) 
        else
        begin 
            showmessage('没有找到当前窗口'); 
            exit;
        end;
        postmessage(wnd,wm_keydown,65,0); 
    end; 
      

  2.   

    postmessage(wnd,wm_keydown,65,0);  
    keydown之后怎么不keyup一下
    sleep(x)
    postmessage(wnd,wm_keyup,65,0);