kristian / system-hook

Global Keyboard / Mouse Hook for Java applications.
MIT License
270 stars 48 forks source link

The raw mode causes my application interface (Swing/JavaFX) to not recieve the events. #17

Open mwss1996 opened 7 years ago

mwss1996 commented 7 years ago

If I instantiate the GlobalKeyboardHook, with a true parameter, my application stops to recieve the key events. The same with GlobalMouseHook, but for mouse events.

I am writing a Swing application, but I have tested the issue with JavaFX to confirm if it was not a Swing specifc problem.

As example, the below JavaFX application becomes unusable:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import lc.kra.system.keyboard.GlobalKeyboardHook;
import lc.kra.system.mouse.GlobalMouseHook;

public class Test extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        GlobalMouseHook mouseHook = new GlobalMouseHook(true);
        GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(true);

        TextField textField = new TextField();
        HBox hBox = new HBox();
        hBox.getChildren().add(textField);
        Scene scene = new Scene(hBox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
kristian commented 7 years ago

Interesting. No idea why this happens yet... According to the Windows documentation raw input should be a plain "listener". Blocking inputs isn't possible. Strange...

mwss1996 commented 7 years ago

hope you can figure it out. I have no ideia.

mdloucks commented 7 years ago

I've been having the same problem with JavaFX text fields, the problem fixes itself once the parameter is changed to 'false', but I hope you can fix the problem!

kristian commented 7 years ago

If raw input is not required, the it's fine to leave the parameter remain false. I can reproduce the problem for both JavaFX and Swing/AWT. Seems strange to me... I hope Java doesn't register a raw input hook itself, otherwise it might runs into problem, as both share the same process ID to register the window handle... Just a wild guess. I hope I can look into this tomorrow.

sirgyula commented 7 years ago

Hello kristian! This problem occurred here too. Have you found any reason for the bug? Do you know any drawback using the hook with raw=false? I'm using win10 prof 1703 and java1.8_144 with JavaFx, if that helps. Thanks!

Fish-In-A-Suit commented 6 years ago

I have been using the SYS in combination with LWJGL api (for the rendering part of my application), and have faced the same issue, where the window just froze when trying to collect input with raw mode. Switching from true to false in the constructor for GlobalMouseHook resolved the issue.

jjYBdx4IL commented 5 years ago

Apparently, it's possible to register hotkey without window resources: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registerhotkey The hwnd parameter is optional. Maybe that helps. If you need the window resource for some reason, maybe add a default mode that is not using it, and an extended mode that can be activated by the user but tells him it may not work.

leopoldhub commented 4 years ago

same problem for me... please fix it ;-;

Zh-Can commented 4 years ago

I've been having the same problem ....

KOConchobhair commented 4 years ago

Hello @kristian just stumbled across your library and this issue...could it perhaps be related to not calling DefRawInputProc(&input, 1, sizeof(RAWINPUTHEADER)); after GetRawInputData(...)?

See the post here where the author states,

Finally, we call Def­Raw­Input­Proc to allow default processing to occur. This lets the keypress enter the normal input system.

kristian commented 4 years ago

Good catch @KOConchobhair and would fit the issue quite well. Unfortunately no success on my side... I added it anyways in c9463895324c5b467f0b8535dbd90a440006645d / 3.8, as I think it's good to have it in. The issue w/ Java is still not solved though... Shame.