Home > Net >  Consult: c # surveillance sweep code gun, qr code
Consult: c # surveillance sweep code gun, qr code

Time:01-24

C # to write the program, to monitor flicking code gun qr code, and sometimes can do it, and sometimes not,,
A great god to solve it,,, online, etc., quite urgent
Integral only so much,,

Hook type, used to install and uninstall hooks
 
///& lt; Summary>
///to start listening to
///& lt;/summary>
///& lt; Returns>
Public bool Start ()
{
_qrCode. The Clear ();
If (_hookProc==null | | _hookHandle==IntPtr. Zero)
_hookProc=KeyboardHookProc;
//get a pointer
IntPtr inpp=Kernel32Library. GetModuleHandle (Process. GetCurrentProcess (). The MainModule. ModuleName);
//add Hook
_hookHandle=User32Library. SetWindowsHookEx ((int) HookType WH_KEYBOARD_LL, _hookProc, inpp, 0).
Running=true;
return true;
}

///& lt; Summary>
///stop listening
///& lt;/summary>
///& lt; Returns>
Public bool Stop ()
{
Bool unhookSuccess=false;
If (_hookHandle!=null | | _hookHandle!=IntPtr. Zero)
{
UnhookSuccess=User32Library. UnhookWindowsHookEx (_hookHandle);
_hookHandle=IntPtr. Zero;
Running=false;
}
Return unhookSuccess;
}

///& lt; Summary>
///hook callback function
///& lt;/summary>
///& lt; Param name="nCode & gt;"
///& lt; Param name="wParam & gt;"
///& lt; Param name="lParam & gt;"
///& lt; Returns>
Private int KeyboardHookProc (int nCode, IntPtr wParam, IntPtr lParam)
{
If (nCode==0)
{
KeyboardMessage MSG=(KeyboardMessage) Marshal. PtrToStructure (lParam, typeof (KeyboardMessage));
_qrCode. Add (MSG);
LogUtility. Info (" Msg analytical value: "+ Msg. VkCode +" qr code scanning code Result: "+ _qrCode. Result);
//vkCode=13 said enter
If (MSG) vkCode==13 & amp; & MSG. ParamH==0 & amp; & ! String. IsNullOrEmpty (_qrCode. Result))
{
QRCodeProcess (_qrCode. Result);
}
}
Return User32Library. CallNextHookEx (IntPtr. Zero, nCode wParam, lParam);
}


Parsing the keyboard
 
///& lt; Summary>
///add the keyboard information
///& lt;/summary>
///& lt; Param name="MSG" & gt;
Public void the Add (KeyboardMessage MSG)
{
# region record key information
//for the first time, press the button
If (_keys. Count==0)
{
_keys=new List (a);
_keys. Add (MSG);
_result=string. The Empty;
}
//not release other button press the button
Else if (_keydown. Count & gt; 0)
{

_keys. Add (MSG);
}
//unit time to press the button
Else if (((TimeSpan) (DateTime. Now - _last)). TotalMilliseconds & lt; The Interval)
{
_keys. Add (MSG);
}
//the new record input
The else
{
_keys=new List (a);
_keys. Add (MSG);
_result=string. The Empty;
}
# endregion

_last=DateTime. Now;

# region for keyboard status
//record is press the button
If (MSG. ParamH==0 & amp; & ! _keydown. The Contains (MSG. VkCode))
{
_keydown. Add (MSG. VkCode);
}
//remove has loosened buttons
If (MSG) paramH & gt; 0 & amp; & _keydown. The Contains (MSG. VkCode))
{
_keydown. Remove (MSG. VkCode);
}
# endregion

# region to calculate the key information
Int v=MSG. VkCode & amp; 0 XFF.
Int c=MSG. ParamL & amp; 0 XFF.
The StringBuilder strKeyName=new StringBuilder (500);
If (User32Library. GetKeyNameText (c * 65536, strKeyName, 255) & gt; 0)
{
_currentKey=strKeyName. ToString (). The Trim (new char [] {', '\ 0'});
User32Library. GetKeyboardState (_state);
If (_currentKey. Length==1 & amp; & MSG. ParamH==0)
{
//according to the state of the keyboard and the shift to cache the output characters
_cur=ShiftChar (_currentKey, isShift, _state). The ToString ();
_result +=_cur;
}
}
# endregion
}

///& lt; Summary>
///
///& lt;/summary>
///& lt; Param name="k" & gt;
///& lt; Param name="isShiftDown & gt;"
///& lt; Param name="state" & gt;
///& lt; Returns>
Private char ShiftChar (string k, bool isShiftDown, byte [] state)
{
Bool capslock=state [0 x14]==1;
Bool numlock=state x90 [0]==1;
Bool scrolllock=state x91 [0]==1;
Bool shiftdown=state xa0 [0]==1;
Char CRH=(capslock? K.T oUpper () : k.T oLower ()). ToCharArray () [0].
If (isShiftDown)
{
If (CRH & gt;='a' & amp; & CRH & lt;='z')
{
CRH=(char) ((int) CRH - 32);
}
Else if (CRH & gt;='A' & amp; & CRH & lt;='Z')
{
If (CRH=='Z')
{
String s="";
}
CRH=(char) ((int) CRH + 32);
}
The else
{
String s="` 1234567890 -=[]; ',./";
The string u="~! @ # $% ^ & amp; * () _ + {} : \ "& lt;> ?" ;
If (s.I ndexOf (CRH) & gt;=0)
{
Return (u.T oCharArray ()) [s.I ndexOf (CRH)];
}
}
}
Return CRH.
}

CodePudding user response:

For help,, online, etc

CodePudding user response:

For help,, online, etc

CodePudding user response:

Somebody else equipment "normal" operating keyboard, what are you doing with a hook?

It is ok to properly deal with the keyboard event programming,
  •  Tags:  
  • C#