我使用互联网上的源代码创建了一个GLOBAL键盘钩子DLL.最好的部分是它非常出色,除了它涉及到浏览器.
它会接收浏览器中的每个键,除了看起来,当浏览器获得焦点时,它会丢失按下的第一个键.在IE和Firefox中进行了测试,两者似乎都是一样的.
例如,如果我打开IE并开始输入www.,我只回来了.如果浏览器窗口保持清晰,则不会丢失其他密钥.一旦浏览器失去焦点并重新获得焦点,第一个键就会再次丢失.
可能是因为只使用WH_KEYDOWN而不是WH_KEYPRESS/WH_KEYUP?有人可以对此有所了解吗?
谢谢
PS:钩子函数本身如下:DLL发送一个备忘录框和应用程序句柄,DLL将发送消息以及用户消息.
function KeyHookFunc(Code, VirtualKey, KeyStroke: Integer): LRESULT; stdcall;
var
KeyState1: TKeyBoardState;
AryChar: array[0..1] of Char;
Count: Integer;
begin
Result := 0;
if Code = HC_NOREMOVE then Exit;
Result := CallNextHookEx(hKeyHook, Code, VirtualKey, KeyStroke);
{I moved the CallNextHookEx up here but if you want to block
or change any keys then move it back down}
if Code < 0 then
Exit;
if Code = HC_ACTION then
begin
if ((KeyStroke and (1 shl 30)) <> 0) then …Run Code Online (Sandbox Code Playgroud)