在铵键精灵中铵一下热键就能在一个文本窗口内输入一串以设好的文本,很想知道其实现方法,各位,多多关照啊!

解决方案 »

  1.   

    我想了解的是:精灵开着,里面设着,按F11是输入文本“我爱DELPHI”字样,我在一个文本框中按F11后,是怎样把上面这句文本输入到文本框内的。[email protected]如果有例子发个给我,谢谢了:)
      

  2.   

    先做个HOOK,勾到了你定义的键就调用下面函数
    sSend 就是那句话
    procedure TOpThread.SendKeys(sSend:string);
    var
        i:integer;
        focushld,windowhld:hwnd;
        threadld:dword;
        ch: byte;
    begin
      windowhld:=GetForegroundWindow;
      threadld:=GetWindowThreadProcessId(Windowhld,nil);
      AttachThreadInput(GetCurrentThreadId,threadld,true);
      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;
    end;