本帖最后由 mywmshow 于 2012-11-01 22:58:11 编辑

解决方案 »

  1.   

    好了我知道了,问题出在:if (wp = VK_HOME) then上。。
    知道吗,wp的值不是虚拟键码,虚拟键码应这样获得:
    vKey:=LoByte(PEventMsg(lp)^.paramL);
    所以if (wp = VK_HOME) then应该为:if (LoByte(PEventMsg(lp)^.paramL) = VK_HOME) then...
      

  2.   


    var
      hFileMap : THandle;
      pShareMem : PAnsiChar;Const
      dwMemSize = 500 * 1024;         //共享内存大小,刚好够就行
      sMapFileName = 'FileMap_2.0_1';procedure ShowSysError;
    var
      S : String;
    begin
      S := '错误原因:' + SysErrorMessage(GetLastError());
      MessageBox(0 , Pointer(S) , '建立共享内存失败' , MB_OK or MB_ICONWARNING);
    end;procedure InitUnit;
    begin
      hFileMap := OpenFileMappingA(FILE_MAP_READ or FILE_MAP_WRITE , False , sMapFileName);
      if hFileMap = 0 then
        hFileMap  := CreateFileMappingA($FFFFFFFF, NIL, PAGE_READWRITE, 0, dwMemSize , sMapFileName);
      if hFileMap = 0 then begin
        ShowSysError;
        exit;
      end;  pShareMem :=  MapViewOfFile(hFileMap , FILE_MAP_WRITE or FILE_MAP_READ , 0 , 0 , 0);
      if pShareMem = nil then begin
        ShowSysError;
        CloseHandle(hFileMap);
        hFileMap := 0;
        exit;
      end;
    end;procedure UnInitUnit;
    begin
      if pShareMem<>NIL then
        UnMapViewOfFile(pShareMem);
      if hFileMap<>0 then
        CloseHandle(hFileMap);
    end;function installKeyProc(GameTid:THandle; DllId:THandle): THandle;
    begin
      if pShareMem=NIL then Result := 0
      else begin
        FillChar(pShareMem^ , dwMemSize , 0);
        StrCopy(pShareMem , '要复制的数据');
        //.......
        KeyHhk := SetWindowsHookEx(WH_KEYBOARD, @Keyproc, DllId, GameTid);
        Result := KeyHhk;
      end;
    end;function keyproc(icode, wp, lp: integer): DWORD; stdcall; //键盘HOOK回调函数
    begin
      if xxxx xxx = VK_HOME then begin
        //.......
        if pShareMem<>NIL then
          MessageBox(0 , pShareMem , '显示数据' , MB_OK);
      end;
      //.......
      Result := CallNextHookEx(KeyHhk, icode, wp, lp);
    end;initialization
      InitUnit;
    finalization
      UnInitUnit;
    end.
      

  3.   

    楼上xxxx xxx = VK_HOME-_-!