I'm currently using jnativhook from: https://github.com/kwhat/jnativehook to listen for nativekeys. I was trying to make a button that waits for a nativekey to be pressed, and sets that input as the new hotkey. Here's what I've tried so far, but when the user clicks it, they have to type the key, and press the button again. It's supposed to allow the user to click on it once, and once there's a input, it'll change the label.
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 com.github.kwhat.jnativehook.mouse.NativeMouseInputListener;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.animation.AnimationTimer;
public class HotKeyWindowController implements NativeKeyListener {
@FXML
private Label stopHotKeyLabel;
@FXML
private Label startHotKeyLabel;
@FXML
private Button stopHotKeyButton;
@FXML
private Button startHotKeyButton;
private static String startKey = "F1";
private static String stopKey = "F3";
private static String key;
public void nativeKeyPressed(NativeKeyEvent e) {
key = NativeKeyEvent.getKeyText(e.getKeyCode());
}
public void stopHotKeyButtonClicked(ActionEvent actionEvent) {
GlobalScreen.removeNativeKeyListener(new HelloApplication());
GlobalScreen.addNativeKeyListener(new HotKeyWindowController());
stopKey = key;
stopHotKeyLabel.setText("Stop HotKey: " + stopKey);
GlobalScreen.addNativeKeyListener(new HelloApplication());
GlobalScreen.removeNativeKeyListener(new HotKeyWindowController());
}
public void startHotKeyButtonClicked(ActionEvent actionEvent) {
}
}