現在系統經常被其他程式提前判斷給處理掉(比如掃碼支付被提前截取處理),于是想自己也寫一個鉤子先判斷。
function keyHookProc(nCode: Integer; LWParam: WPARAM; LLParam: LPARAM): LRESULT;//呼叫鍵盤鉤子,屏蔽功能鍵
var
p: LPKBDLLHOOKSTRUCT;
y: integer;
fFlag:boolean;
KeyName: array[0..100] of char;
Kbs: TKeyboardState;
WChar: array[0..1] of Char;
lpmyshare:pmyshare;
hfocus:hwnd;
begin
fFlag:=false;
if nCode < 0 then
begin
Result:= CallNextHookEx(hHk, nCode, LWParam, LLParam);
Exit;
end
else
begin
y := 1;
case LWParam of
WM_KEYDOWN://, WM_SYSKEYDOWN, WM_KEYUP,WM_SYSKEYUP:
begin
p:= LPKBDLLHOOKSTRUCT(LLParam);
BarCodes_usb.VirtKey:=p.vkCode;
BarCodes_usb.scanCode:=p.scanCode;
GetKeyNameText(BarCodes_usb.scanCode, @KeyName, 100);
BarCodes_usb.KeyName:=KeyName;
GetKeyboardState(Kbs);
// 轉換成字符
if ToAscii(BarCodes_usb.VirtKey,BarCodes_usb.scanCode, Kbs, WChar, 0) = 1 then
begin
// BarCodes_usb.Ascll = uKey;
BarCodes_usb.Chr :=WChar[0];// Convert.ToChar(uKey);
end;
// showmessage(BarCodes_usb.Chr);
if MilliSecondsBetween(now,BarCodes_usb.Time)> 50 then
begin
strBarCode:=BarCodes_usb.Chr;
end
else
begin
//如果是回車
if (p.vkCode = VK_RETURN) and (length(strBarCode)>3) then
begin
BarCodes_usb.BarCode := strBarCode;
BarCodes_usb.IsValid := true;
end;
strBarCode :=strBarCode+BarCodes_usb.Chr;
end;
BarCodes_usb.Time := Now;
//激活事件
FMMain.show_label;
BarCodes_usb.IsValid := false;
if (p.vkCode = VK_RETURN) then strBarCode :='';
if fFlag then y:=0;
end;
end;
if y=1 then
Result:=1 //如果為WIN功能鍵則屏蔽
else
Result:= 0;//CallNextHookEx(hHk, nCode, LWParam, LLParam); //其他鍵放下一個鉤子
end
end;
現在問題是這個鉤子可以判斷輸入的字串,但如何才能做到把這個字串再根據需要是否回寫呢?
比如輸入 12345 系統不處理,原來的輸入框顯示12345
輸入123456 鉤子就處理,不顯示到輸入框那?
別的程式就是這么實作的。輸入一定的規則就不顯示,否則和正常一樣。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/285040.html
上一篇:snap7拿個API能夠檢測PLC與上位機的連接狀態?
下一篇:淺談零基礎學習java的自學方法
