kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.73k stars 345 forks source link

Monitoring the input of the barcode scanner may result in partial data loss #466

Open YiXiXiao opened 3 months ago

YiXiXiao commented 3 months ago

Hi, When I am using the jcef framework to develop Windows desktop programs, I use jnativehook to listen to the barcode scanner and keyboard input. When I use the barcode scanner to continuously and quickly scan the code, there may be a shortage of execution of the NativeKeyListener callback method. For example, barcode 6901028240410 has a total of 13 digits, but nativeKeyTyped only executes 12 times, resulting in outputs of 6, 9, 0, 1, 2, 8, 2, 4, 0, 4, 1, 0. My program is as follows:

private void registerScanListener() { try { scanLogger.setLevel(java.util.logging.Level.OFF); GlobalScreen.setEventDispatcher(new SwingDispatchService()); GlobalScreen.registerNativeHook(); } catch (NativeHookException e) { e.printStackTrace(); }

    GlobalScreen.addNativeKeyListener(new NativeKeyListener() {
        @Override
        public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {
          if (Character.isLetterOrDigit(nativeKeyEvent.getKeyCode())) {
              System.out.println(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode()));
          }
        }

        @Override
        public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {

        }

        @Override
        public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {

        }
    });
}
kwhat commented 3 months ago

I believe this is resolved in the . 3 relase, but I don't have a build yet.

kwhat commented 3 months ago

If you look at the debug log, do you get a message about restarting the hook?

YiXiXiao commented 3 months ago

If you look at the debug log, do you get a message about restarting the hook?

I'm very sorry, I haven't found any logs related to hook restart, and this issue may only occur when scanning quickly and continuously.

When will version. 3 be available?

Thank you very much!

liaoliang commented 2 months ago

barcode input type may lose charactor, how to solve