键盘事件

发布于 2024-10-30 04:43:39 字数 455 浏览 1 评论 0原文

我需要监听来自特定键盘设备的键盘事件知道在 (C#) WPF 应用程序中按下了哪个键。理想情况下,这不应该依赖于窗口,并且只要应用程序具有焦点就可以工作。

不幸的是我想不出/找到任何方法来做到这一点。

有什么想法吗?

博士

编辑:我一直在研究OpenTK.Input< /a> 库,它有一个很好的按键界面...有谁知道如何在不创建 GameWindow 的情况下获取 KeyboardDevice

信息: 顺便说一句,这是对于模拟键盘的条形码扫描仪......谁的好主意是,嗯?

I need to listen for keyboard events from a specific keyboard device & know which key is pressed in a (C#) WPF application. Ideally, this shouldn't be window dependant and work so long as the application has focus.

unfortunately I can't think of / find any way to do this.

any ideas?

D.R

Edit: I've been looking into the OpenTK.Input library, which has a nice interface for keys... Does anybody know how to get a KeyboardDevice without creating a GameWindow

Info: Just by the way, this is for a barcode scanner which emulates a keyboard... who's bright idea was that, eh?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月流歌 2024-11-06 04:43:39

我实际上正在做一个项目,正是这样做的。查看 Kaptivate。它安装一个全局键盘钩子,并将原始输入 api 连接在一起(使用魔法),然后调用回调函数,以便您可以决定(1)这就是我想要的设备吗?(2)我应该允许其他应用程序可以查看它,或者只是为自己保留击键。目前只有 C++,但最终目标之一是拥有 C# 包装器。

对于键盘,每个生成的事件都会告诉您 vkey、扫描代码和源设备。

I'm actually working on a project that does exactly that. Check out Kaptivate. It installs a global keyboard hook, and ties together (using magic) the raw input api, and then invokes a callback function so that YOU can decide (1) is this the device I'm after?, and (2) should I allow other apps to see it, or just keep the keystroke for myself. Right now it's only C++ but one of the goals is eventually to have C# wrappers.

For keyboards, each generated event tells you the vkey, scan code, and source device.

只是偏爱你 2024-11-06 04:43:39

看看下面2篇文章。

在 WPF / C# 中使用全局键盘挂钩 (WH_KEYBOARD_LL)< /a>

https://gist.github.com/471698

两者都应该正是您想要的。 ..

Have a look at the below 2 articles.

Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#

https://gist.github.com/471698

both should be exactly what you want...

箹锭⒈辈孓 2024-11-06 04:43:39

设法在msdn上找到这个教程 。以及 POS.Net SDK

我还没有真正有时间来分解它是如何工作的,还没有给出适当的概述,但似乎我应该能够为任何“键盘楔子”编写自定义服务对象抽象HID 设备。

Managed to find this tutorial on msdn. along with a Sample Scanner object which comes with the POS.Net SDK

I haven't really had the time to pick apart how it works yet to give a proper overview, but it seems I should be able to write a custom service object abstraction for any "keyboard wedge" HID device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文