当前位置: 首页> 文旅> 艺术 > 海口海南网站建设_工业设计网站导航_搜索引擎排名优化seo课后题_b2b电商平台有哪些

海口海南网站建设_工业设计网站导航_搜索引擎排名优化seo课后题_b2b电商平台有哪些

时间:2025/8/23 23:24:18来源:https://blog.csdn.net/qq_34047402/article/details/147286089 浏览次数:0次
海口海南网站建设_工业设计网站导航_搜索引擎排名优化seo课后题_b2b电商平台有哪些

        RawInputSharp 是一个 C# 库,用于处理 Windows 的原始输入(Raw Input) API,它允许开发者直接访问键盘、鼠标等输入设备的底层数据。

        本例介绍如何读取键盘的虚拟码以及键盘硬件信息。效果如下图:

        示例中:开始是1键的按下与抬起; 然后是shift+1键的按下与抬起。

          注意shift的虚拟键是16. 因为是手按的shift晚抬起:shift按下->1按下->1抬起->shift抬起。

        具体实现步骤如下:

1.    通过NuGet包安装 RawInput.Sharp.

2. 实际代码如下:

 public partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.SourceInitialized += MainWindow_SourceInitialized;        }private void MainWindow_SourceInitialized(object sender, EventArgs e){var windowInteropHelper = new WindowInteropHelper(this);var hwnd = windowInteropHelper.Handle;// Get the devices that can be handled with Raw Input.var devices = RawInputDevice.GetDevices();var keyboards = devices.OfType<RawInputKeyboard>();foreach (var item in keyboards){Console.WriteLine(item.DevicePath);}// register the keyboard device and you can register device which you need like mouseRawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink, hwnd);HwndSource source = HwndSource.FromHwnd(hwnd);source.AddHook(Hook);}private IntPtr Hook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled){const int WM_INPUT = 0x00FF;try{// You can read inputs by processing the WM_INPUT message.if (msg == WM_INPUT){// Create an RawInputData from the handle stored in lParam.var data = RawInputData.FromHandle(lparam);// You can identify the source device using Header.DeviceHandle or just Device.var sourceDeviceHandle = data.Header.DeviceHandle;var sourceDevice = data.Device;// The data will be an instance of either RawInputMouseData, RawInputKeyboardData, or RawInputHidData.// They contain the raw input data in their properties.switch (data){case RawInputKeyboardData keyboard:if (keyboard.Device == null || keyboard.Device.DevicePath == null){break;}Console.WriteLine(keyboard.Device.DevicePath + "----" + keyboard.Keyboard);                            break;}}}catch (Exception ex){;}return IntPtr.Zero;}}

关键字:海口海南网站建设_工业设计网站导航_搜索引擎排名优化seo课后题_b2b电商平台有哪些

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: