Why does my keyboard manipulator get the same key-up and key-down event multiple times?

In my previous question , I reported that when scanning a barcode, the keyboard hook reported all two times.

I put this on key and key events and got good tips.

Looking at it more closely, I found that each figure actually represents a report four times!

Here's a rough "fingerprint debugging". Can anyone suggest what I may be doing wrong? Need more info? I could just ignore every second entry, but ... yes! I would better understand what is happening.

That's what I got for one digit 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

Update: here is my code

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;

-. .

+5
1

, Code. KeyboardProc callback function :

HC_NOREMOVE              wParam lParam , . ( PeekMessage , PM_NOREMOVE.)

,

   if Code < 0 then  
   begin
      Result := CallNextHookEx(KBHook, Code, WordParam, LongParam);
      Exit;
   end;

   if (Code < 0) or (Code = HC_NOREMOVE ) then
   begin
      Result := CallNextHookEx(KBHook, Code, wparam, lparam);
      Exit;
   end;
+9

All Articles