关于KeyBoardHook使用的一个问题:急!急!急!急!急!急!(50分)

  • 主题发起人 主题发起人 wind1278wind
  • 开始时间 开始时间
W

wind1278wind

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在做了一个全局键盘钩子。但是不知怎的,我不能在里面申请全局变量。
我得设计思路如下:
我要把键盘的键值转换。如果你输入是VK_ENTER我让他显示给用户的是‘1’。
现在这个我是实现了。就是我把VK_ENTER改成可以变得,而且要从文件中读取。可
每次变量都不成功。请问那位高手能帮我解决。
 
为什么每次变量都会被自动清空?有谁知道不妨告诉我一下。我很急!
 
Library KbdHook;
Uses Windows;

Type
PVars = ^TVars;
TVars =
Record
HHook :HHook;
LKeys :String[255];
Shift :Boolean;
End;
Var
MapHandle :THandle;
Vars :PVars;
Function GetKey(Code:LongInt):Char;
var I:Integer;
begin
Result := #0;
I := MapVirtualKey(Code,2);
If I < $FF then
Result := Chr(Byte(I));
end;
Function KeybUpper(C:Char):Char;
Const
SFrom = '1234567890+.,<';
STo = '!"#¤%&/()=?:;>';
begin
If Pos(C,SFrom) > 0 then
Result := STo[Pos(C,SFrom)]
Else
Result := C;
CharUpperBuff(@Result,1);
end;
Function KeybHook(Code:Integer; WParam:WParam; LParam:LParam):LResult; StdCall; Export;
var C:Char;
begin
Result := 0;
If Code > 0 then
Result := CallNextHookEx(Vars.HHook,Code,WParam,LParam);
If Code = HC_ACTION then
If ((LParam shr 31) and 1 > 0) then Begin // Got a key_down
Asm
CLI
End;
C := GetKey(WParam);
If { Caps } (Lo(GetKeyState(VK_CAPITAL)) = 0) xor { Shift } Vars.Shift then // Upcase
C := KeybUpper(C)
Else
CharLowerBuff(@C,1);
Vars.LKeys := Vars.LKeys + C;
If WParam = VK_SHIFT then
Vars.Shift := True;
Asm
STI
End;
End Else Begin // Got a key_up
If WParam = VK_SHIFT then
Vars.Shift := False;
End;
end;
Function InstallKeybHook:HHook; StdCall; Export;
begin
Vars.HHook := SetWindowsHookEx(WH_KEYBOARD,KeybHook,hInstance,0);
Result := Vars.HHook;
end;
Procedure GetLastKey(Var C:Char); StdCall; Export;
begin
Asm
CLI
End;
If Length(Vars.LKeys) = 0 then
C := #0
Else Begin
C := Vars.LKeys[1];
Delete(Vars.LKeys,1,1);
End;
Asm
STI
End;
end;
Procedure DLLEntryPoint(dwReason:DWord);
var Init:Boolean;
begin
Case dwReason of
DLL_PROCESS_ATTACH:
Begin
MapHandle := CreateFileMapping($FFFFFFFF,Nil,PAGE_READWRITE,0,SizeOf(TVars),'_KeyLogger');
Init := GetLastError <> ERROR_ALREADY_EXISTS;
If MapHandle = 0 then
Exit;
Vars := MapViewOfFile(MapHandle,FILE_MAP_ALL_ACCESS,0,0,0);
If Vars = Nil then Begin
CloseHandle(MapHandle);
Exit;
End;
If Init then Begin
FillChar(Vars^,SizeOf(TVars),0);
End;
End;
DLL_PROCESS_DETACH:
Begin
UnmapViewOfFile(Vars);
CloseHandle(MapHandle);
End;
DLL_THREAD_ATTACH:;
DLL_THREAD_DETACH:;
End;
end;
Exports KeybHook index 1,InstallKeybHook index 2,GetLastKey index 3;
begin
DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
 
lilofox:请问你的dll怎么用出参太多。还有你的值是写死的。我要他可以变吗?
能不能给一个详细一点的程序,最好有个Demo程序。再此,谢谢了!
 
来个清楚的。这个是最清楚的了,可以随便加入功能了。
library HookDll;

uses
Windows,
Messages,
SysUtils;

{Define a record for recording and passing information process wide}
type
PHookRec = ^THookRec;
THookRec = packed record
TheHookHandle : HHOOK;
TheAppWinHandle : HWND;
TheCtrlWinHandle : HWND;
TheKeyCount : DWORD;
end;

var
hObjHandle : THandle; {Variable for the file mapping object}
lpHookRec : PHookRec; {Pointer to our hook record}


procedure MapFileMemory(dwAllocSize : DWORD);
begin
{Create a process wide memory mapped variable}
hObjHandle := CreateFileMapping($FFFFFFFF,
NIL,
PAGE_READWRITE,
0,
dwAllocSize,
'HookRecMemBlock');
if (hObjHandle = 0) then begin
MessageBox(0,
'Hook DLL',
'Could not create file map object',
MB_OK);
exit;
end;
{Get a pointer to our process wide memory mapped variable}
lpHookRec := MapViewOfFile(hObjHandle,
FILE_MAP_WRITE,
0,
0,
dwAllocSize);
if (lpHookRec = NIL) then begin
CloseHandle(hObjHandle);
MessageBox(0,
'Hook DLL',
'Could not map file',
MB_OK);
exit;
end;
end;


procedure UnMapFileMemory;
begin
{Delete our process wide memory mapped variable}
if (lpHookRec <> NIL) then begin
UnMapViewOfFile(lpHookRec);
lpHookRec := NIL;
end;
if (hObjHandle > 0) then begin
CloseHandle(hObjHandle);
hObjHandle := 0;
end;
end;


function GetHookRecPointer : pointer stdcall;
begin
{Return a pointer to our process wide memory mapped variable}
result := lpHookRec;
end;


{The function that actually processes the keystrokes for our hook}
function KeyBoardProc(Code : integer;
wParam : integer;
lParam : integer): integer; stdcall;
var
KeyUp : bool;
{Remove comments for additional functionability
IsAltPressed : bool;
IsCtrlPressed : bool;
IsShiftPressed : bool;
}
begin
result := 0;

case Code of
HC_ACTION : begin
{We trap the keystrokes here}

{Is this a key up message?}
KeyUp := ((lParam AND (1 shl 31)) <> 0);

(*Remove comments for additional functionability
{Is the Alt key pressed}
if ((lParam AND (1 shl 29)) <> 0) then begin
IsAltPressed := TRUE;
end else begin
IsAltPressed := FALSE;
end;

{Is the Control key pressed}
if ((GetKeyState(VK_CONTROL) AND (1 shl 15)) <> 0) then begin
IsCtrlPressed := TRUE;
end else begin
IsCtrlPressed := FALSE;
end;

{if the Shift key pressed}
if ((GetKeyState(VK_SHIFT) AND (1 shl 15)) <> 0) then begin
IsShiftPressed := TRUE;
end else begin
IsShiftPressed := FALSE;
end;
*)

{If KeyUp then increment the key count}
if (KeyUp <> FALSE) then begin
Inc(lpHookRec^.TheKeyCount);
end;

case wParam of

{Was the enter key pressed?}
VK_RETURN : begin
{if KeyUp}
if (KeyUp <> FALSE) then begin
{Post a bogus message to the window control in our app}
PostMessage(lpHookRec^.TheCtrlWinHandle,
WM_KEYDOWN,
0,
0);
PostMessage(lpHookRec^.TheCtrlWinHandle,
WM_KEYUP,
0,
0);
end;
{If you wanted to swallow the keystroke then return -1}
{else if you want to allow the keystroke then return 0}
result := 0;
exit;
end; {VK_RETURN}

{If the left arrow key is pressed then lets play a joke!}
VK_LEFT : begin
{if KeyUp}
if (KeyUp <> FALSE) then begin
{Create a UpArrow keyboard event}
keybd_event(VK_RIGHT, 0, 0, 0);
keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
end;
{Swallow the keystroke}
result := -1;
exit;
end; {VK_LEFT}

end; {case wParam}
{Allow the keystroke}
result := 0;
end; {HC_ACTION}
HC_NOREMOVE : begin
{This is a keystroke message, but the keystroke message}
{has not been removed from the message queue, since an}
{application has called PeekMessage() specifying PM_NOREMOVE}
result := 0;
exit;
end;
end; {case code}
if (Code < 0) then
{Call the next hook in the hook chain}
result :=
CallNextHookEx(lpHookRec^.TheHookHandle,
Code,
wParam,
lParam);
end;

procedure StartKeyBoardHook; stdcall;
begin
{If we have a process wide memory variable}
{and the hook has not already been set...}
if ((lpHookRec <> NIL) AND
(lpHookRec^.TheHookHandle = 0)) then begin
{Set the hook and remember our hook handle}
lpHookRec^.TheHookHandle := SetWindowsHookEx(WH_KEYBOARD,
@KeyBoardProc,
hInstance,
0);
end;
end;


procedure StopKeyBoardHook; stdcall;
begin
{If we have a process wide memory variable}
{and the hook has already been set...}
if ((lpHookRec <> NIL) AND
(lpHookRec^.TheHookHandle <> 0)) then begin
{Remove our hook and clear our hook handle}
if (UnHookWindowsHookEx(lpHookRec^.TheHookHandle) <> FALSE) then
begin
lpHookRec^.TheHookHandle := 0;
end;
end;
end;


procedure DllEntryPoint(dwReason : DWORD);
begin
case dwReason of
Dll_Process_Attach : begin
{If we are getting mapped into a process, then get}
{a pointer to our process wide memory mapped variable}
hObjHandle := 0;
lpHookRec := NIL;
MapFileMemory(sizeof(lpHookRec^));
end;
Dll_Process_Detach : begin
{If we are getting unmapped from a process then, remove}
{the pointer to our process wide memory mapped variable}
UnMapFileMemory;
end;
end;
end;


exports
KeyBoardProc name 'KEYBOARDPROC',
GetHookRecPointer name 'GETHOOKRECPOINTER',
StartKeyBoardHook name 'STARTKEYBOARDHOOK',
StopKeyBoardHook name 'STOPKEYBOARDHOOK';

begin
DLLProc := @DllEntryPoint;
DllEntryPoint(Dll_Process_Attach);
end.
 
能不能给一个使用他的例子。你的出口太多,我看得不太明白。
 
在线等待,你的答复!
 
仔细看看就知道啊,GetHookRecPointer就是你要的全局变量啊,在KeyBoardProc处理你的按键啊。
 
我怎么调用这个dll文件。。。。。。你的出口函数有:
KeyBoardProc name 'KEYBOARDPROC',
GetHookRecPointer name 'GETHOOKRECPOINTER',
StartKeyBoardHook name 'STARTKEYBOARDHOOK',
StopKeyBoardHook name 'STOPKEYBOARDHOOK';
我在应用程序中怎么调用这几个函数
 
type
// functions prototypes for the hook dll
TGetHookRecPointer = function: Pointer; stdcall;
TPauseHook = procedure (Pause: Boolean); stdcall;
TGetPauseStatus = function: Boolean; stdcall;
TStartKeyBoardHook = procedure; stdcall;
TStopKeyBoardHook = procedure; stdcall;

// record type filled in by the hook dll}
THookRec = packed record
TheHookHandle: HHOOK;
TheAppWinHandle: HWND;
TheCtrlWinHandle: HWND;
TheKeyCount: DWORD;
TheMessage: UINT;
isPaused: Boolean;
end;

// pointer type to the hook record}
PHookRec = ^THookRec;




const
Hook_Dll = 'KeyHOOKDLL.DLL';
kbAlt = $0001;
kbCtrl = $0002;
kbShift = $0004;

var
hHookLib: THandle; // handle to the hook dll
// function pointers
GetHookRecPointer: TGetHookRecPointer;
StartKeyboardHook: TStartKeyBoardHook;
StopKeyboardHook: TStopKeyBoardHook;
GetPauseStatus: TGetPauseStatus;
PauseHook: TPauseHook;
LibLoadSuccess: Boolean = False; // is the hook lib was successfully loaded?
lpHookRec: PHookRec = nil; // pointer to the hook record
MessageToIntercept: UINT;

ExitRequest: Boolean = False;

procedure initUnit;
@GetHookRecPointer := nil;
@StartKeyboardHook := nil;
@StopKeyboardHook := nil;
@PauseHook := nil;
@GetPauseStatus := nil;

hHookLib := LoadLibrary(Hook_Dll);
// now get the addresses for the procs
if hHookLib <> 0 then
begin
@GetHookRecPointer :=
GetProcAddress(hHookLib, 'GETHOOKRECPOINTER');
@StartKeyboardHook :=
GetProcAddress(hHookLib, 'STARTKEYBOARDHOOK');
@StopKeyboardHook :=
GetProcAddress(hHookLib, 'STOPKEYBOARDHOOK');
@PauseHook :=
GetProcAddress(hHookLib, 'PAUSEHOOK');
@GetPauseStatus :=
GetProcAddress(hHookLib, 'GETPAUSESTATUS');
// check if we get everything correctly
if (@GetHookRecPointer <> nil) and
(@StartKeyboardHook <> nil) and
(@StopKeyboardHook <> nil) and
(@PauseHook <> nil) and
(@GetPauseStatus <> nil) then
begin
LibLoadSuccess := True;
lpHookRec := GetHookRecPointer;
if lpHookRec <> nil then
begin
lpHookRec^.TheHookHandle := 0;
lpHookRec^.TheKeyCount := 0;
lpHookRec^.TheCtrlWinHandle := Handle;
lpHookRec^.TheMessage := MessageToIntercept;
// start!
Timer1.Enabled := True;
StartKeyboardHook;
end else
begin
// something's wrong... we can't find some function(s)
FreeLibrary(hHookLib);
hHookLib := 0;
@GetHookRecPointer := nil;
@StartKeyboardHook := nil;
@StopKeyboardHook := nil;
@PauseHook := nil;
@GetPauseStatus := nil;
end;
end;
end;

NeedReturn := False;
 
unit HookProc;
{CASE 语句中的值按键盘的矩阵排列:
第一排从左到右;第二排从左到右;第三排从左到右;第四排从
左到右;左面从上到下;右面从上到下,。。。把CASE 值换成
要处理的键盘的对应键值。本程序适合的键盘排列为:“123上
移”;“456修改”;“789下移”;“取消 0 。确认”;“左
面从上到下四个键”;“右面从上到下四个键”。}

interface
uses
IniFiles,Windows, SysUtils;
const
afilename='c:/key.txt';
var
HNextHookProc:hhook;
ProcSaveExit:pointer;
{定义键盘的键值变量}

type
PKey = ^TKey;
TKey = packed record
KeyEnter:Longint;
KeyEscape:Longint;
KeyClear:Longint;
KeyUp:Longint;
KeyDown:Longint;
end;

var
MapHandle: THandle;
Keys: PKey;

function KeyBoardHook(iCode:Integer;wparam:WPARAM;lparam:LPARAM):LResult;stdcall;export;
function SetKeyHook:bool;export;//加载钩子
function EndKeyHook:bool;export;//卸载钩子
procedure KeyHookExit;far;
procedure MapFileMemory(dwAllocSize : DWORD);
procedure UnMapFileMemory;
procedure wrec(str:string);
procedure ReadIni;

implementation

procedure MapFileMemory(dwAllocSize : DWORD);
begin
{Create a process wide memory mapped variable}
MapHandle := CreateFileMapping($FFFFFFFF,
NIL,
PAGE_READWRITE,
0,
dwAllocSize,
'HookRecMemBlock');
if (MapHandle = 0) then
begin
exit;
end;
{Get a pointer to our process wide memory mapped variable}
Keys := MapViewOfFile(MapHandle,
FILE_MAP_WRITE,
0,
0,
dwAllocSize);
if (Keys = NIL) then begin
CloseHandle(MapHandle);
exit;
end;
end;

procedure UnMapFileMemory;
begin
{Delete our process wide memory mapped variable}
if (Keys <> NIL) then begin
UnMapViewOfFile(Keys);
Keys := NIL;
end;
if (MapHandle > 0) then begin
CloseHandle(MapHandle);
MapHandle := 0;
end;
end;

Procedure ReadIni;
Var
IniF:TIniFile;
begin
IniF:=TIniFile.Create('./Ini/KeyOpt.ini');
Try
Keys.KeyEnter:=IniF.ReadInteger('Param','Enter',0);
Keys.KeyEscape:=IniF.ReadInteger('Param','Esc',0);
Keys.KeyClear:=IniF.ReadInteger('Param','Clear',0);
Keys.KeyUp:=IniF.ReadInteger('Param','Up',0);
Keys.KeyDown:=IniF.ReadInteger('Param','Down',0);
Finally
Inif.Free;
end;
end;

procedure wrec( str:string);
var
debugfile:TextFile;
begin
if FileExists(afilename) then
begin
assignfile(debugfile,afilename);
append(debugfile);
write(debugfile,#10);
write(debugfile,#13);
write(debugfile,'[');
write(debugfile,str);
write(debugfile,']');
closefile(debugfile);
end
else begin
assignfile(debugfile,afilename);
rewrite(debugfile);
write(debugfile,'[');
write(debugfile,str);
write(debugfile,']');
closefile(debugfile);
end;
end;

function KeyBoardHook(iCode:Integer;wparam:WPARAM;lparam:LPARAM):LResult;
var
I:tagINPUT;
bp:^Byte;
Inif:TIniFile;
begin
Result:=0;
if iCode<0 then
begin
Result:=CallNextHookEx(HNextHookProc,iCode,wParam,lParam);
Exit;
end;
bp:=@lParam;
inc(bp);
inc(bp);
//wrec(inttostr(wParam));
if lParam>0 then
begin
if bp^<>$FE then
begin
sleep(5);
wrec(IntTostr(Keys.KeyEnter));
if wParam=Keys.KeyClear then
begin
//wrec('I have Reciver back key');
i.Itype:=input_keyboard;
i.ki.wVk:=221;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end
else if wParam=Keys.KeyEnter then
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$48;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end
else if wParam=Keys.KeyEscape then
begin
//wrec('I have Rec Tab key');
i.Itype:=input_keyboard;
i.ki.wVk:=82;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end
else if wParam=Keys.KeyUp then
begin
i.Itype:=input_keyboard;
i.ki.wVk:=38;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end
else if wParam=Keys.KeyDown then
begin
i.Itype:=input_keyboard;
i.ki.wVk:=40;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end
else
case wParam of
97: // '1'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$42;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
98: // '2'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$4E;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
99: //'3'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=77;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
100: //'4'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=79;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
101: //'5'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$50;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
102: //'6'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=219;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
103: //'7'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$51;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
104: //'8'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=$57;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
105: //'9'
begin
i.Itype:=input_keyboard;
i.ki.wVk:=69;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
96:
begin // ‘0’
i.Itype:=input_keyboard;
i.ki.wVk:=68;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
110: // dot
begin
i.Itype:=input_keyboard;
i.ki.wVk:=70;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
119: //F8 左1
begin
i.Itype:=input_keyboard;
i.ki.wVk:=84;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
118: //左2
begin
i.Itype:=input_keyboard;
i.ki.wVk:=89;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
117: //左3
begin
i.Itype:=input_keyboard;
i.ki.wVk:=85;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;

116: //左4
begin
i.Itype:=input_keyboard;
i.ki.wVk:=73;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
115: //右1
begin
i.Itype:=input_keyboard;
i.ki.wVk:=74;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
114: //右2
begin
i.Itype:=input_keyboard;
i.ki.wVk:=75;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;

113: //右3
begin
i.Itype:=input_keyboard;
i.ki.wVk:=76;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
112: // F1 //右4
begin
i.Itype:=input_keyboard;
i.ki.wVk:=186;//ord('d');//字符0变成1;
i.ki.wScan:=$FE;
i.ki.dwFlags:=1;
SendInput(1, i,sizeof(i)); //模拟键盘
Result:=1;
Exit;
end;
else
Result:=0;
end;
end;
end
else
Result:=1;
end;

function SetKeyHook:bool;
var
bResult:BOOL;
Init: Boolean;
begin
bResult:=False;
//-----------------------------------------
MapHandle := 0;
Keys := NIL;
MapFileMemory(sizeof(Keys^));
//----------------------------------------
ReadIni;
HNextHookProc:=SetWindowsHookEx(WH_KEYBOARD,keyboardhook,HInstance,0);
if(HNextHookProc <> 0) then
bResult:=True;
Result:=bResult;
end;

function EndKeyHook:bool;
begin
if HNextHookProc<>0 then
begin
UnhookWindowsHookEx(HNextHookProc);
HNextHookProc:=0;
Result:=True;
Exit;
end;
HNextHookProc:=0;
//----------------------
UnMapFileMemory;
//----------------------
Result:=False;
end;

procedure KeyHookExit;
begin
if HNextHookProc<>0 then
EndKeyHook;
ExitProc:=ProcSaveExit;
end;
end.
你看一下我的程序为什么不行,我用你的内存映射文件也不行。你帮我看一下吧谢谢!
 
你的意思好象我不太明白了,你要怎样做了?
 
接受答案了.
 
后退
顶部