Skip to content

Commit

Permalink
快捷键关闭日志
Browse files Browse the repository at this point in the history
  • Loading branch information
4379711 committed Apr 24, 2024
1 parent 3572002 commit 277fb32
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/yalong/site/services/hotkey/HotKeyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import lombok.extern.slf4j.Slf4j;
import org.jnativehook.GlobalScreen;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author yalong
*/
Expand All @@ -25,7 +28,13 @@ private synchronized void hook() {
return;
}
try {
GlobalScreen.registerNativeHook();
//关闭日志
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
logger.setUseParentHandlers(false);
if(!GlobalScreen.isNativeHookRegistered()){
GlobalScreen.registerNativeHook();
}
} catch (Exception e) {
log.error("hook按键失败", e);
throw new RuntimeException(e);
Expand All @@ -35,7 +44,9 @@ private synchronized void hook() {
Runtime run = Runtime.getRuntime();
run.addShutdownHook(new Thread(() -> {
try {
GlobalScreen.unregisterNativeHook();
if(GlobalScreen.isNativeHookRegistered()){
GlobalScreen.unregisterNativeHook();
}
} catch (Exception e) {
log.error("取消hook按键失败", e);
}
Expand Down

0 comments on commit 277fb32

Please sign in to comment.