I have to catch a hotkey of Ctrl+Alt+C, C
(meaning, press Ctrl+Alt+C
, release only C
and press it again). Here is what I\'m trying to do:<
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.