在my previous question中,我報告說,掃描條形碼時,鍵盤鉤子報告了所有內容。爲什麼我的鍵盤掛鉤多次接收到相同的鍵盤鍵和鍵盤鍵事件?
我把它放下來,關鍵事件&,並收到了很好的建議。
仔細看了看,我發現每個數字實際上都是報告四次!
這裏是一個粗略的「打印調試」。任何人都可以建議我可能做錯了什麼?你需要更多信息嗎?我可能只是忽略每一秒的輸入,但... yeuck!我寧願明白髮生了什麼。
這就是我得到了一個數字2
---------
LongParam = 196609 | Word = 50 | 2
LongParam and $80000000 = 0
LongParam and $40000000 = 0
---------
LongParam = 196609 | Word = 50 | 2
LongParam and $80000000 = 0
LongParam and $40000000 = 0
---------
LongParam = -1073545215 | Word = 50 | 2
LongParam and $80000000 = 2147483648
LongParam and $40000000 = 1073741824
---------
LongParam = -1073545215 | Word = 50 | 2
LongParam and $80000000 = 2147483648
LongParam and $40000000 = 1073741824
更新:這裏是我的代碼
function KeyboardHookProc(Code: Integer; WordParam: Word; LongParam: LongInt): LongInt; stdcall;
begin
if Code < 0 then // http://msdn.microsoft.com/enus/library/windows/desktop/ms644984%28v=vs.85%29.aspx
begin
Result := CallNextHookEx(KBHook, Code, WordParam, LongParam);
Exit;
end;
MainForm.Memo1.Lines.Add('---------');
MainForm.Memo1.Lines.Add('LongParam = ' + IntToStr(LongParam) + ' | Word = ' + IntToStr(Ord(WordParam)) + ' | ' + Char(WordParam));
MainForm.Memo1.Lines.Add('LongParam and $80000000 = ' + IntToStr(LongParam and $80000000));
MainForm.Memo1.Lines.Add('LongParam and $40000000 = ' + IntToStr(LongParam and $40000000));
if ((LongParam and $80000000) <> $80000000) (* not key up *)
or ((LongParam and $40000000) <> $40000000) (* key was not previously down *)
then
begin
Result := CallNextHookEx(KBHook, Code, WordParam, LongParam);
Exit;
end;
if MainForm.ScanningChemical = False then
begin
Result := CallNextHookEx(KBHook, Code, WordParam, LongParam);
Exit;
end;
在這一點上我有一個條形碼數字。但是這些備忘錄行在此之前添加了。
嘗試包括代碼,您正在使用處理鍵盤鉤來幫助你。 – RRUZ 2012-03-26 02:47:46
已添加1個代碼。我試圖擺脫關鍵並只處理關鍵,但我似乎收到每個 – Mawg 2012-03-26 03:18:24