Java 两个独立键盘的单独输入 [英] Java Separate Input of Two Separate Keyboards

查看:39
本文介绍了Java 两个独立键盘的单独输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一台机器上插入了两个 USB 键盘.我正在开发一个 Java 应用程序.无论如何允许Java应用程序分离出它来自哪个USB键盘?(即是否有类似 http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html 但有一个 USB 参数,所以我可以知道它来自哪个 USB 设备?)

I have two USB keyboards plugged into the same machine. I am developing a Java application. Is there anyway to allow the Java Application to separate out which USB keyboard it came from? (I.e. is there something like http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html but with a USB parameter so I can know which USB device it came from?)

谢谢!

推荐答案

这在单独的 Java 中是不可能的.

This is not possible with Java alone.

但是有 3rd 方工具可以重新映射键盘的按键.HID 宏 是一种应用程序.但它仅适用于按键,不适用于按键向上和向下事件.这限制了它的实用性,但对于您的用例来说可能已经足够了.

But there are 3rd party tools that can remap the keys of a keyboard. HID macros is one application. But it only works with key presses, not key-up and -down events. This limits it's usefulness but might be enough for your usecase.

如果你想深入挖掘,你需要使用 RAW Input API 在 Windows 上执行您想要的操作.代码项目已经有一个很好的例子,标题为 使用来自 C# 的原始输入来处理多个键盘 阐明了正确的 API 用法.

If you want to dig deeper you need to use the RAW Input API on Windows to do what you want. There's already a nice example on code project titled Using Raw Input from C# to handle multiple keyboards that sheds some light on the correct API usage.

这篇关于Java 两个独立键盘的单独输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆