commit init

This commit is contained in:
weihongyang
2022-06-20 16:26:51 +08:00
commit 7aaa6700b3
171 changed files with 9178 additions and 0 deletions

27
ym-barcode/pom.xml Normal file
View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ym-pass</artifactId>
<groupId>com.cnbm</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ym-barcode</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.github.kwhat</groupId>
<artifactId>jnativehook</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,91 @@
package com.cnbm.barcode.listener;
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 lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* @Author weihongyang
* @Date 2022/6/20 4:08 PM
* @Version 1.0
*/
@Log4j2
@Component
public class GlobalKeyListenerExample implements NativeKeyListener {
static {
try {
GlobalScreen.registerNativeHook();
} catch (NativeHookException e) {
throw new RuntimeException(e);
}
GlobalScreen.addNativeKeyListener(new GlobalKeyListenerExample());
}
protected final static LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue();
public void nativeKeyPressed(NativeKeyEvent e) {
log.info("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
try {
queue.put(e.getKeyCode());
} catch (InterruptedException ex) {
ex.printStackTrace();
}
int[] hotKeyArray1 = {NativeKeyEvent.VC_X, NativeKeyEvent.VC_Y,NativeKeyEvent.VC_Z};
if (queue.size() == 5 && e.getKeyCode() == NativeKeyEvent.VC_ENTER && judgeCombinationKey(hotKeyArray1)){
String result = "";
List<String> collect = queue.stream().map(n -> {
return NativeKeyEvent.getKeyText(n);
}).collect(Collectors.toList());
for (String s : collect) {
result = result + s;
}
log.info("符合标准的扫码是:"+ result);
queue.clear();
}
if (queue.size() == 6){
queue.poll();
}
if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
try {
GlobalScreen.unregisterNativeHook();
} catch (NativeHookException nativeHookException) {
nativeHookException.printStackTrace();
}
}
}
protected Boolean judgeCombinationKey(int[] hotKeyArray){
Object[] queueKey = queue.toArray();
Predicate<int[]> keyArrayPredicateOne = hotKeies -> (int)queueKey[0] == hotKeies[0]
&& (int)queueKey[1] == hotKeies[1]
&& (int)queueKey[2] == hotKeies[2];
Predicate<int[]> keyArrayPredicateTwo = hotKeies -> (int)queueKey[1] == hotKeies[0]
&& (int)queueKey[2] == hotKeies[1]
&& (int)queueKey[3] == hotKeies[2];
return queue.size() == 3 ? keyArrayPredicateOne.test(hotKeyArray) :
keyArrayPredicateOne.or(keyArrayPredicateTwo).test(hotKeyArray);
}
public void nativeKeyReleased(NativeKeyEvent e) {
log.info("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
}
public void nativeKeyTyped(NativeKeyEvent e) {
log.info("Key Typed: " + e.getKeyText(e.getKeyCode()));
}
}