我编写了个无窗口程序,但无法响应键盘.
在程序中直接用键盘钩子,无法拦到键盘按下
用dll钩子因无窗口程序无HWND,无法通讯,而且不希望用dll
用int中断,系统说我没有这个权限
怎么办?

解决方案 »

  1.   

    天,消息需要什么东西为载体,就是窗体啊,如果你没有窗体,系统要将消息发送给谁。你应该了解了一下Windows编程的基本原理。
      

  2.   

    program JimPoint;uses
      Windows,
      Messages,
      HookKeyBoard;{$R *.res}var
      KBH   : TSystemKeyBoard;
      KeyS  : String;//对拦截到的键处理
    procedure RecKeyBoard(Sender: TObject; var Key: Word;
        Shift: TShiftState);
    begin
      if CheckKey then
        KeyS := KeyS + Chr(Key);
    end;begin
      KBH           := TSystemKeyBoard.Create;
      KBH.OnKeyDown := @RecKeyBoard;
      KBH.Open;
      while GetMessage(aMessage,0,0,0) do begin
        TranslateMessage(amessage);
        DispatchMessage(aMessage);
      end;
      KBH.Close;
      KBH.Free;
      Halt(aMessage.wParam);
    end.
    //HookKeyBoard单元,去http://blog.csdn.net/kiboisme/找
      

  3.   

    if CheckKey then//这个函数可以不要,就是用来判断是否需要保存的。
      

  4.   

    那你要响应系统发送给其他程序的键盘鼠标当然可以,用日志钩子。
    这里看看:http://blog.csdn.net/linzhengqun
      

  5.   

    to 各位高人
    {$R *.res}
    var
    function HookProc(nCode:Integer;wParam:wParam;lParam:lParam) : LRESULT ; stdcall;
    begin//经测试键盘按下后没有经过这里(下断点,textout等方法)为什么????/
    end;
    begin
    HookID := SetWindowsHookEx(WH_JOURNALRECORD, HookProc ,HInstance,0);
    HOOKID可以获取
    ……//循环
     UnHookWindowsHookEx(HookID); 
    end.
      

  6.   

    仔细地看这两篇文章:
    http://blog.csdn.net/linzhengqun/archive/2005/10/06/496074.aspx
    http://blog.csdn.net/linzhengqun/archive/2005/10/06/496076.aspx
      

  7.   

    不就是一个SetWindowHookEx和一个钩子处理过程吗,都是调用Windows的API,不可能会增加多少体积的,
    你为什么不试试再说呢。