修改过的条码钩子
来源:互联网 发布:网络公司财务 编辑:程序博客网 时间:2024/05/03 00:49
public class BarCodeHook{ public delegate void BarCodeDelegate(BarCodes barCode); public event BarCodeDelegate BarCodeEvent; public struct BarCodes { public int VirtKey; //虚拟码 public int ScanCode; //扫描码 public string BarCode; //条码信息 public bool IsValid; //条码是否有效 public DateTime Time; //扫描时间 } private struct EventMsg { public int message; public int paramL; public int paramH; public int Time; public int hwnd; } [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] private static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] private static extern bool UnhookWindowsHookEx(int idHook); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] private static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam); [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string name); delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); BarCodes barCode = new BarCodes(); int hKeyboardHook = 0; List<char> _barcode = new List<char>(100); private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam) { if (nCode == 0) { EventMsg msg = (EventMsg)Marshal.PtrToStructure(lParam, typeof(EventMsg)); if (wParam == 0x100) //WM_KEYDOWN = 0x100 { barCode.VirtKey = msg.message & 0xff; //虚拟码 barCode.ScanCode = msg.paramL & 0xff; //扫描码 //if (DateTime.Now.Subtract(barCode.Time).TotalMilliseconds > 100) //{ // _barcode.Clear(); //} //else //{ // if ((msg.message & 0xff) == 13 && _barcode.Count > 0) //回车 // { // barCode.BarCode = new String(_barcode.ToArray()); // barCode.IsValid = true; // _barcode.Clear(); // } //} //barCode.Time = DateTime.Now; //if (BarCodeEvent != null) BarCodeEvent(barCode); //触发事件 //barCode.IsValid = false; //_barcode.Add(Convert.ToChar(msg.message & 0xff)); if ((msg.message & 0xff) == 13 && _barcode.Count > 0) //回车 { barCode.BarCode = new String(_barcode.ToArray()); barCode.IsValid = true; _barcode.Clear(); if (BarCodeEvent != null) { BarCodeEvent(barCode);//触发事件 } } else { barCode.IsValid = false; _barcode.Add(Convert.ToChar(msg.message & 0xff)); } } } return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); } private static HookProc hookproc; // 安装钩子 public bool Start() { if (hKeyboardHook == 0) { hookproc = new HookProc(KeyboardHookProc); //WH_KEYBOARD_LL = 13 //hKeyboardHook = SetWindowsHookEx(13, hookproc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0); hKeyboardHook = SetWindowsHookEx(13, hookproc, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);//解决返回0的问题 } return (hKeyboardHook != 0); } // 卸载钩子 public bool Stop() { if (hKeyboardHook != 0) { return UnhookWindowsHookEx(hKeyboardHook); } return true; }}
0 0
- 修改过的条码钩子
- 条码打印软件如何修改条码线的密度
- CodeIgniter 中过的钩子流程
- C#下usb条码扫描枪的钩子实现的改进
- 全局钩子过TP
- 修改按键的回调钩子函数
- 钩子函数对键盘消息的修改
- 修改zxing连续扫描条码和二维码的怪问题
- 键盘钩子修改键值
- Delphi中利用钩子实现QQ聊天窗口的修改
- Delphi利用钩子实现QQ窗口的修改
- 允许用户修改svn日志的钩子脚本
- 允许用户修改svn日志的钩子脚本
- 允许用户修改svn日志的钩子脚本
- Delphi中利用钩子实现QQ聊天窗口的修改
- 什么是条码?使用条码的益处是什么?
- 什么是钩子,钩子的原理
- 修改过的PHP购物车类
- USB子系统的树形结构
- 内存堆和栈的区别
- 记录学习的点滴(Git入门)
- 生成图片二维码
- iOS CocoaPods iOS 'The sandbox is not sync with the Podfile.lock'问题解决
- 修改过的条码钩子
- storyboard中出现的问题
- Python抓取gb2312字符集网页中文乱码
- xxx is not in the sudoers file.This incident will be reported.的解决方法
- yii1.0 细小累计
- 计划任务,但可能不能运行,因为无法设置帐户信息,指定的错误是:0X80041315
- java_mail收发邮件
- 在浏览器中禁止拖动页面的元素或者拖动图片打开新的窗口
- web配置p6spy