有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

键盘Java键捕捉器

我想用Java制作一种键盘记录器。我有一个应用程序,允许人们在桌面上获取RSS提要,我想快速访问。 顺便说一下,我需要一些可以做到这一点的东西:

  • 我启动javajar文件,并在系统托盘中将其最小化
  • 用户做他想做的事(冲浪、看电影等)
  • 他按下一个组合键(CTRL+I),然后java窗口打开并显示一个GUI,在那里他可以查看新闻并修改应用程序配置
  • 现在,他可以最小化窗口(系统托盘图标),继续正常使用电脑

我的应用程序必须完全跨平台。除此功能外,所有操作都已完成。 我曾尝试使用KeyStroke甚至System.in来实现这一点,但它们仅在用户将窗口设置为活动状态时捕捉组合键

那么,有没有一种方法可以不使用JNI或JNA(我的搜索结果就是这样)就从应用程序外部捕获密钥组合(比如透明覆盖)

谢谢你的帮助


共 (2) 个答案

  1. # 1 楼答案

    不,您必须转到一些依赖于系统的库,即使用某种形式的JNI

    不同的内置粒度级别包括:

    WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

    Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.

    WHEN_FOCUSED

    Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus.

    WHEN_IN_FOCUSED_WINDOW

    Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component

  2. # 2 楼答案

    这是不可能做到的。在当今世界,没有哪个操作系统能让你记录所有的击键行为