Skip to content

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

@YiXiXiao

Description

@YiXiXiao

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) {

        }
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions