使用Java,如何在不使用GUI组件的情况下检测按键? [英] Using Java, How to detect keypresses without using GUI components?

查看:167
本文介绍了使用Java,如何在不使用GUI组件的情况下检测按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java,可以在不使用GUI元素的情况下检测用户操作,例如按键,鼠标按钮和/或鼠标的屏幕位置?

Using Java, is it possible to detect user actions, such as key-presses, mouse-button-presses, and/or mouse's screen location, without the use of GUI elements?

如果是,我该如何实现?

If it is, how could I implement it?

否则有哪些替代方案?

我在这个问题上发现的唯一StackOverflow源是这个问题,这是未得到答复的。

The only StackOverflow source i found on this matter is this question, which is unanswered.

StackOverflow在这个问题上指向一个不可见的GUI解决方案,希望是我真的想避免的东西。

And the only sources I found outside StackOverflow on this matter point to an "Invisible GUI" solution, wish is something i really want to avoid.

推荐答案

它可以实现使用JNI和/或JNA,但这不能真正被称为java实现,因为您必须编写平台特定的本机代码。

It can be implemented using JNI and/or JNA but this cannot be really called "java implementation" because you will have to write platform specific native code.

我尝试的替代解决方案是使用全屏透明寡居,正在监听鼠标和键盘的所有事件,并使用类<$ c将其转发到真实的应用程序$ C>机器人。我试过这种方法它适用于一个限制:支持应用程序的鼠标悬停事件有问题:鼠标不会移动到真正的应用程序。它正在移动透明的java窗口。

Alternative solution I tried is to use full screen transparent widow that is listening to all events of mouse and keyboard and "forwards" them to the real application using class Robot. I tried this approach. It works well with one limitation: there is a problem to support "mouse over" events of applications: the mouse is not moving over the real application. It is moving over the transparent java window.

这篇关于使用Java,如何在不使用GUI组件的情况下检测按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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