部分解决方案可以使用键盘挂钩 ( WH_KEYBOARD_LL ) 来捕获特殊组合键或单个键,然后使用keybd_event函数发送(替换)另一个击键。
试试这个拦截 VK_UP
密钥并发送一个示例代码S
var
hhk: HHOOK;
function CBT_FUNC(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
type
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
TKBDLLHOOKSTRUCT = record
vkCode: cardinal;
scanCode: cardinal;
flags: cardinal;
time: cardinal;
dwExtraInfo: Cardinal;
end;
PKeyboardLowLevelHookStruct = ^TKeyboardLowLevelHookStruct;
TKeyboardLowLevelHookStruct = TKBDLLHOOKSTRUCT;
var
LKBDLLHOOKSTRUCT: PKeyboardLowLevelHookStruct;
begin
case nCode of
HC_ACTION:
begin
LKBDLLHOOKSTRUCT := PKeyboardLowLevelHookStruct(lParam);
if (LKBDLLHOOKSTRUCT^.vkCode = VK_UP) then
begin
if (wParam=WM_KEYUP) or (wParam=WM_SYSKEYUP)then
keybd_event( Ord('S'), 0, KEYEVENTF_KEYUP, 0)
else
keybd_event( Ord('S'), 0, 0, 0);
Exit(1); //eat the key
end;
end;
end;
Result := CallNextHookEx(hhk, nCode, wParam, lParam);
end;
Procedure InitHook();
begin
hhk := SetWindowsHookEx(WH_KEYBOARD_LL, @CBT_FUNC, 0, 0);
if hhk=0 then RaiseLastOSError;
end;
Procedure KillHook();
begin
if (hhk <> 0) then
UnhookWindowsHookEx(hhk);
end;
initialization
InitHook();
finalization
KillHook();
end.
在使用这种钩子之前记得阅读文档,特别是备注部分。