R
rebeccarice
Unregistered / Unconfirmed
GUEST, unregistred user!
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
var
aHandle:THandle;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_F11) < 0) then
begin
Result := 1;
aHandle := FindWindow('NotePad',nil);
if aHandle <> 0 then
begin
SetForeGroundWindow(aHandle);
aHandle := GetWindow(aHandle,GW_Child);
PostMessage(aHandle,WM_KEYDOWN,VK_Control,0);
PostMessage(aHandle,WM_KEYDOWN,Byte('v'),0);
PostMessage(aHandle,WM_KEYUP,Byte('v'),0);
PostMessage(aHandle,WM_KEYUP,VK_Control,0);
end;
end;
end;
程序如上,这是在hook 中对键盘的监控,如果按了‘F11’,就模拟‘Ctrl+V’这个组合键,
但是结果却不对。如果用SendKey('^V',False) 这个函数,他就会模拟按键很多遍。
请各位大侠帮忙!
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
var
aHandle:THandle;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_F11) < 0) then
begin
Result := 1;
aHandle := FindWindow('NotePad',nil);
if aHandle <> 0 then
begin
SetForeGroundWindow(aHandle);
aHandle := GetWindow(aHandle,GW_Child);
PostMessage(aHandle,WM_KEYDOWN,VK_Control,0);
PostMessage(aHandle,WM_KEYDOWN,Byte('v'),0);
PostMessage(aHandle,WM_KEYUP,Byte('v'),0);
PostMessage(aHandle,WM_KEYUP,VK_Control,0);
end;
end;
end;
程序如上,这是在hook 中对键盘的监控,如果按了‘F11’,就模拟‘Ctrl+V’这个组合键,
但是结果却不对。如果用SendKey('^V',False) 这个函数,他就会模拟按键很多遍。
请各位大侠帮忙!