如何在java中捕获全局键按下 [英] How to capture global key presses in java

查看:249
本文介绍了如何在java中捕获全局键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Java创建了一个简单的媒体播放器,但我想要记录全局按键,如 Ctrl + P 来暂停/恢复当前正在播放音乐没有JFrame有焦点但似乎由于JVM安全问题而无法播放。

I made a simple Media player in Java but I want to record global key presses like Ctrl + P to pause/resume the current music being played without the JFrame having focus but it seems that its not possible due to JVM security issues.

我遇到了 JNativeHook 但我想仅针对Windows实现自己的方法。
请建议如何操作以及从哪里开始?

I came across JNativeHook but I want to implement my own method only for Windows. Please Suggest how to do it and where to begin ?

推荐答案

Jintellitype是一个有点简单的解决方案。

Jintellitype is a somewhat easy solution.

https://code.google.com/p / jintellitype /

另一个简单的解决方案是使用带JNA的Windows钩子:

The other easy solution would be to use a windows hook with JNA:

Windows中的JNA键盘挂钩

我对JNA有一些经验并且非常喜欢api。

I have some experience with JNA and have really liked the api.

第三种解决方案是使用JNI管理您自己的呼叫。

And a third solution would be to manage your own calls with JNI.

据我所知,可移植性方面,就响应用户输入而言,windows dlls和api架构已保留在不同的操作系统版本中。如果内存服务,用户输入的钩子在user32 dll中。也许你必须为x64位版本跳过一些箍,但我怀疑它会那么难。

Portability-wise, as far as I know, windows dlls and api architecture as far as responding to user input, has been preserved in different OS versions. If memory serves, hooks for user input are in the user32 dll. Maybe you have to jump through some hoops for a x64 bit version, but I doubt it would be that hard.

这篇关于如何在java中捕获全局键按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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