Catch a “double” hotkey

女生的网名这么多〃 提交于 2019-12-02 03:35:00

You can register a global hotkey only once, but you can receive its events in the handler many times. So the basic idea is to save the last time your saw this key and if two are coming between certain delay, you have a double click:

    var last = 0l
    val listener = new HotKeyListener() {
      def onHotKey(hotKey: HotKey): Unit = {
        hotKey.keyStroke match {
          case `ctrlC` =>
            if (System.currentTimeMillis() - last < 700) // arbitrary delay of 700 ms
              println("We have a double click!")
            else last = System.currentTimeMillis()
        }
      }
    }

if you want something without var, I guess you can wrap it in a Promise or something.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!