-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support customised shortcut key system (#72)
- Loading branch information
1 parent
bfe3b34
commit 25ee935
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
composeApp/src/desktopMain/kotlin/com/clipevery/listen/GlobalListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.clipevery.listen | ||
|
||
import com.github.kwhat.jnativehook.GlobalScreen | ||
import com.github.kwhat.jnativehook.NativeHookException | ||
|
||
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent | ||
|
||
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
|
||
val logger = KotlinLogging.logger {} | ||
|
||
class GlobalListener { | ||
|
||
init { | ||
try { | ||
GlobalScreen.registerNativeHook() | ||
} catch (ex: NativeHookException) { | ||
logger.error { "There was a problem registering the native hook." } | ||
logger.error { "ex.message" } | ||
} | ||
GlobalScreen.addNativeKeyListener(GlobalKeyListenerExample()) | ||
} | ||
|
||
} | ||
|
||
|
||
class GlobalKeyListenerExample : NativeKeyListener { | ||
override fun nativeKeyPressed(e: NativeKeyEvent) { | ||
logger.info { "Key Pressed: " + NativeKeyEvent.getKeyText(e.keyCode) } | ||
if (e.keyCode == NativeKeyEvent.VC_ESCAPE) { | ||
try { | ||
GlobalScreen.unregisterNativeHook() | ||
} catch (nativeHookException: NativeHookException) { | ||
nativeHookException.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
override fun nativeKeyReleased(e: NativeKeyEvent) { | ||
logger.info { "Key Released: " + NativeKeyEvent.getKeyText(e.keyCode) } | ||
} | ||
|
||
override fun nativeKeyTyped(e: NativeKeyEvent) { | ||
logger.info { "Key Typed: " + NativeKeyEvent.getKeyText(e.keyCode) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters