Reset keyboard state when window is deactivated/reactivated

This commit is contained in:
Brendan Robert 2016-01-03 16:43:31 -06:00
parent 732f4768a6
commit ca6a831020
3 changed files with 12 additions and 2 deletions

View File

@ -58,7 +58,7 @@ public class JaceApplication extends Application {
while (Emulator.computer.getVideo() == null || Emulator.computer.getVideo().getFrameBuffer() == null) { while (Emulator.computer.getVideo() == null || Emulator.computer.getVideo().getFrameBuffer() == null) {
Thread.yield(); Thread.yield();
} }
controller.connectComputer(Emulator.computer); controller.connectComputer(Emulator.computer, primaryStage);
bootWatchdog(); bootWatchdog();
}); });
primaryStage.setOnCloseRequest(event -> { primaryStage.setOnCloseRequest(event -> {

View File

@ -10,6 +10,7 @@ import com.sun.glass.ui.Application;
import jace.cheat.MetaCheat; import jace.cheat.MetaCheat;
import jace.core.Card; import jace.core.Card;
import jace.core.Computer; import jace.core.Computer;
import jace.core.Keyboard;
import jace.library.MediaCache; import jace.library.MediaCache;
import jace.library.MediaConsumer; import jace.library.MediaConsumer;
import jace.library.MediaConsumerParent; import jace.library.MediaConsumerParent;
@ -43,6 +44,7 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.stage.Stage;
/** /**
* *
@ -79,10 +81,11 @@ public class JaceUIController {
rootPane.setOnDragExited(this::processDragExitedEvent); rootPane.setOnDragExited(this::processDragExitedEvent);
} }
public void connectComputer(Computer computer) { public void connectComputer(Computer computer, Stage primaryStage) {
this.computer = computer; this.computer = computer;
appleScreen.setImage(computer.getVideo().getFrameBuffer()); appleScreen.setImage(computer.getVideo().getFrameBuffer());
EventHandler<KeyEvent> keyboardHandler = computer.getKeyboard().getListener(); EventHandler<KeyEvent> keyboardHandler = computer.getKeyboard().getListener();
primaryStage.setOnShowing(evt->computer.getKeyboard().resetState());
rootPane.setFocusTraversable(true); rootPane.setFocusTraversable(true);
rootPane.setOnKeyPressed(keyboardHandler); rootPane.setOnKeyPressed(keyboardHandler);
rootPane.setOnKeyReleased(keyboardHandler); rootPane.setOnKeyReleased(keyboardHandler);

View File

@ -39,6 +39,7 @@ import java.util.logging.Logger;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.stage.WindowEvent;
/** /**
* Keyboard manages all keyboard-related activities. For now, all hotkeys are * Keyboard manages all keyboard-related activities. For now, all hotkeys are
@ -50,6 +51,12 @@ import javafx.scene.input.KeyEvent;
*/ */
public class Keyboard implements Reconfigurable { public class Keyboard implements Reconfigurable {
public void resetState() {
clearStrobe();
openApple(false);
solidApple(false);
}
private Computer computer; private Computer computer;
public Keyboard(Computer computer) { public Keyboard(Computer computer) {