The code below
Private int KeyboardHookProc (int nCode, Int32 wParam, IntPtr lParam)
{
BarCode. IsValid=false;
Bool notChar=false;
If (nCode==0)
{
EventMsg MSG=(EventMsg) Marshal. PtrToStructure (lParam, typeof (EventMsg));
If (wParam==0 x100)//WM_KEYDOWN=0 x100
{
BarCode. VirtKey=MSG. Message & amp; 0 XFF.//virtual code
BarCode. ScanCode=MSG. ParamL & amp; 0 XFF.//scan code
The StringBuilder strKeyName=new StringBuilder (255);
If (GetKeyNameText (barCode ScanCode * 65536, strKeyName, 255) & gt; 0)
{
BarCode. KeyName=strKeyName. ToString (). The Trim (new char [] {', '\ 0'});
}
The else
{
BarCode. KeyName="";
}
Byte [] kbArray=new byte [256].
Uint uKey=0;
The GetKeyboardState (kbArray);//the key state Chinese lost!!!!!!
If (ToAscii (barCode. VirtKey, barCode. ScanCode kbArray, ref uKey, 0))
{
BarCode. AscII=uKey;
//the Console. WriteLine (uKey);
BarCode. CRH=the Convert. ToChar (uKey);
}
The else
{
NotChar=true;//turn to ASCII characters of failure, this is not a normal character, to remove
}
If (DateTime. Now. Subtract (barCode. Time). TotalMilliseconds & gt; 30)//30 ms can filter out continuous press a button,
the condition of the{
If (notChar==false)
StrBarCode=barCode. CRH. The ToString ();
The else
StrBarCode="";
BarCode. IsValid=false;
}
The else
{
If (strBarCode. Length & gt;
=5){
BarCode. IsValid=true;//isValid to true indicates that this is a bar code
}
If (notChar==false)
{
StrBarCode +=barCode. CRH. The ToString ();
}
BarCode. BarCode=strBarCode;
}
BarCode. Time=DateTime. Now;
If (BarCodeEvent!=null & amp; & BarCode. IsValid) BarCodeEvent (barCode);//triggers
}
}
Return CallNextHookEx (hKeyboardHook, nCode wParam, lParam);
}
CodePudding user response:
In accordance with the equipment manufacturer examples of programming design, normally (don't need programming) to deal with the application of key event, don't waste time, low-level don't need to do anything,CodePudding user response:
If I let a person programming, then I know that this man hole my money and I asked him to write a simple program, he gave me to hook the bottom, do? Just because he wants to achieve a method called BarCodeEvent hook the bottom? Then don't use such developers,CodePudding user response:
The landlord to solve this problem?CodePudding user response:

CodePudding user response:
https://blog.csdn.net/superwfei/article/details/101005215CodePudding user response:
You didn't the device interface or the SDK, if you can use USB read binary data can use c # version of the qr code parsing library parsing can,