【问题标题】:How to cause a left click then turn off thread?如何导致左键单击然后关闭线程?
【发布时间】:2015-10-20 16:25:42
【问题描述】:
    private void runInBackground() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (running) {
                try {
                    checkPixel();
                } catch (AWTException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
}

public void stop() {
    this.running = false;
}

public void start() {
    this.running = true;
}

所以我有一些有人提供给我的代码来监控屏幕中间的颜色变化。我想在按下 F9 之类的东西后基本上打开/关闭checkPixel(),但是如果没有 GUI,我怎么能做到这一点,因为我似乎找不到任何允许这样做的东西。我相信 KeyListener 只适用于 GUI?

编辑:好的,所以当我检查线程中的像素变化时。一旦检测到像素变化,我想在checkPixel() 中创建一个“左键单击操作”,然后关闭线程。有什么帮助吗?

【问题讨论】:

  • 如何在没有 GUI 的情况下添加 KeyListener?除非我错了
  • stackoverflow.com/questions/901224/… ...不幸的是...或者您可以使用全屏透明窗口,然后实现 KeyListener。我可能会选择全屏透明窗口,因为它会节省你很多时间
  • @peggy 我已经进行了编辑,你能帮忙吗?也许这是一个更聪明的解决方案。我们不必再次启动线程。
  • 我仍然会使用透明窗口/KeyListener,但我相信还有其他方法可以实现您的目标

标签: java multithreading keylistener


【解决方案1】:

我猜你想要 JNativeHook 库提供的功能。 该库允许从背景中获取密钥。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 2014-06-10
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    相关资源
    最近更新 更多