Home > Net >  C # USB qr code scanner Chinese reading processing problem
C # USB qr code scanner Chinese reading processing problem

Time:10-04

This several days to develop a program to use USB qr code scanner reads Chinese 2 yards, handled the basic idea is to use the virtual keyboard, but found that after dealing with Chinese content all is lost, who dealt with such problems,
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:

internal interface and, from the unit to automatically take pictures, if you want to gain recognition after data please open its own code driver (exe), monitor the clipboard can,

CodePudding user response:

https://blog.csdn.net/superwfei/article/details/101005215

CodePudding 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,
  •  Tags:  
  • C#
  • Related