Home > Back-end >  How to judge whether a return after the keyboard hook to get?
How to judge whether a return after the keyboard hook to get?

Time:05-26

Now system is often other programs judgment in advance to dispose of them (such as sweep yards to pay in advance intercept processing), and also want to write a hook to judgment,


The function keyHookProc (nCode: Integer; LWParam: WPARAM; LLParam: LPARAM) : LRESULT;//call the keyboard hook shielding function keys
Var
P: LPKBDLLHOOKSTRUCT;
Y: integer;
FFlag: Boolean;
KeyName: an array of char [0.. 100];

Kbs: TKeyboardState;
WChar: an array of Char [0.. 1];

Lpmyshare: pmyshare;
Hfocus: HWND;

The begin
FFlag:=false;
If nCode & lt; 0 then
The begin
Result:=CallNextHookEx (hHk, nCode LWParam, LLParam);
The Exit;
End
The else
The begin
Y:=1;
Case LWParam of
WM_KEYDOWN://,, WM_KEYUP, WM_SYSKEYDOWN WM_SYSKEYUP:
The begin

P:=LPKBDLLHOOKSTRUCT (LLParam);

BarCodes_usb. VirtKey:=p.v kCode;
BarCodes_usb. ScanCode:=p. canCode;

GetKeyNameText (BarCodes_usb scanCode, @ KeyName, 100);
BarCodes_usb. KeyName:=KeyName;

The GetKeyboardState (Kbs);

//convert characters
If ToAscii (BarCodes_usb VirtKey, BarCodes_usb scanCode, Kbs, WChar, 0)=1 then
The begin
//BarCodes_usb. Ascll=uKey;
BarCodes_usb. CRH:=WChar [0].//the Convert. ToChar (uKey);
end;
//showmessage (BarCodes_usb. CRH);
If MilliSecondsBetween (now, BarCodes_usb. Time) & gt; 50 then
The begin
StrBarCode:=BarCodes_usb. CRH;
End
The else
The begin
//if the enter
If (p.v kCode=VK_RETURN) and (length (strBarCode) & gt; 3) then
The begin
BarCodes_usb. BarCode:=strBarCode;
BarCodes_usb. IsValid:=true;
end;
StrBarCode:=strBarCode + BarCodes_usb. CRH;
end;
BarCodes_usb. Time:=Now;

//activate event
FMMain. Show_label;


BarCodes_usb. IsValid:=false;


If (p.v kCode=VK_RETURN) then strBarCode:=' ';


If fFlag then: y=0;

end;
end;
If y=1 then
Result:=1//if to WIN the function keys are shielding
The else
Result:=0;//CallNextHookEx (hHk, nCode LWParam, LLParam);//other key down a hook
End
end;


Now the problem is this hook can determine the input string, but how to do the string according to whether need to write again?

12345 system does not handle such as input, the original input box shows 12345
Enter 123456 hooks processing, don't show to input box?
That's what other program implementation, input certain rules and will not display and normal,

  • Related