diff --git a/.idea/misc.xml b/.idea/misc.xml index 6aecfa7..32ddfac 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,5 +11,5 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3bc5a94..57c94df 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 UTF-8 - 8 + 11 true @@ -42,6 +42,13 @@ hutool-all 5.8.26 + + + + com.melloware + jintellitype + 1.4.0 + diff --git a/src/main/java/com/example/jmacro/wjdr/util/Capture.java b/src/main/java/com/example/jmacro/wjdr/util/Capture.java new file mode 100644 index 0000000..a9dcf38 --- /dev/null +++ b/src/main/java/com/example/jmacro/wjdr/util/Capture.java @@ -0,0 +1,85 @@ +package com.example.jmacro.wjdr.util; + +import cn.hutool.log.StaticLog; +import com.melloware.jintellitype.HotkeyListener; +import com.melloware.jintellitype.JIntellitype; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; + +/** + * 辅助截屏工具 + */ +public class Capture extends JFrame { + + // 退出 + private final int KEY_MARK_ESC = 1; + + public Capture() { + init(); + } + + private void init() { + setExtendedState(Frame.MAXIMIZED_BOTH); + setLocation(0, 0);//位置 + setUndecorated(true); + setAlwaysOnTop(true); + setBackground(new Color(0, 0, 0, 0.4f)); + + // 监听窗口关闭 + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + // 关闭应用时要释放资源 + dispose(); + System.exit(0);//0正常退出,1非正常退出 + } + }); + + // 添加热键 + JIntellitype.getInstance().registerHotKey(KEY_MARK_ESC, 0, KeyEvent.VK_ESCAPE); + JIntellitype.getInstance().addHotKeyListener(hotkeyListener); + + setVisible(true); + } + + private final HotkeyListener hotkeyListener = new HotkeyListener() { + @Override + public void onHotKey(int i) { + switch (i) { + case KEY_MARK_ESC: { + StaticLog.info("exit."); + JIntellitype.getInstance().unregisterHotKey(KEY_MARK_ESC); + JIntellitype.getInstance().removeHotKeyListener(hotkeyListener); + close(); + } + break; + } + } + }; + + + public void close() { + // 关闭应用时要释放资源 + dispose(); + System.exit(0); + } + + + public static void main(String[] args) { + int originX = 0; + int originY = 0; + + File legend = new File("legend"); + + + System.out.println("请将鼠标移动截图位置的左上角,并且按下Ctrl"); + + + Capture capture = new Capture(); + } +}