我有一个WIN32 SDK的例子,想要的话,EMAIL:[email protected]

解决方案 »

  1.   

    先将以下的文字剪贴存成HKTest.DPR
    library HKTest;uses
      HKProc in 'HKProc.pas';exports
      EnableHotKeyHook,
      DisableHotKeyHook;begin
      hNextHookProc := 0;
      procSaveExit := ExitProc;
      ExitProc := @HotKeyHookExit;
    end.将以下的文字剪贴存成HKProc.PAS
    unit HKProc;interfaceuses
      Windows, Messages;var
      hNextHookProc: HHook;
      procSaveExit: Pointer;function KeyboardHookHandler(iCode: Integer;
      wParam: WPARAM;
      lParam: LPARAM): LRESULT; stdcall; export;
    function EnableHotKeyHook: BOOL; export;
    function DisableHotKeyHook: BOOL; export;
    procedure HotKeyHookExit; far;implementationfunction KeyboardHookHandler(iCode: Integer;
      wParam: WPARAM;
      lParam: LPARAM): LRESULT; stdcall; export;
    const
      _KeyPressMask = $80000000;
    begin
      Result := 0;
      If iCode < 0 Then
      begin
        Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
        Exit;
      end;
      if ((lParam and _KeyPressMask) = 0) and
        (GetKeyState(vk_Control) < 0) and (wParam = Ord('B')) then
      begin
        Result := 1;
        WinExec('Notepad.exe', sw_Normal);
      end;
    end;function EnableHotKeyHook: BOOL; export;
    begin
      Result := False;
      if hNextHookProc <> 0 then Exit;
      hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,
        KeyboardHookHandler,
        HInstance,
        0);
      Result := hNextHookProc <> 0;
    end;function DisableHotKeyHook: BOOL; export;
    begin
      if hNextHookProc <> 0 then
      begin
        UnhookWindowshookEx(hNextHookProc);
        hNextHookProc := 0;
        MessageBeep(0);
        MessageBeep(0);
      end;
      Result := hNextHookProc = 0;
    end;procedure HotKeyHookExit;
    begin
      if hNextHookProc <> 0 then DisableHotKeyHook;
      ExitProc := procSaveExit;
    end;end.启动Delphi开启HKTest.DPR,然後Project  and  Build All以产生HKTest.DLLFile  and  New Application 存到与HKTest.DLL相同的目录中.在Form1上安置二个TButton,并撰写OnClick程式implementation{$R *.DFM}function EnableHotKeyHook: BOOL; external 'HKTEST.DLL';
    function DisableHotKeyHook: BOOL; external 'HKTEST.DLL';procedure TForm1.Button1Click(Sender: TObject);
    begin
      if EnableHotKeyHook then
        ShowMessage('HotKey Testing...');
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      if DisableHotKeyHook then
        ShowMessage('HotKey Testing..., DONE!!');
    end;end.
      

  2.   

    我己经把这个例子改写成一个可以监视键盘上都输入些什么的dll了。谁要啊?