Skip to content
Snippets Groups Projects
Commit 69c8bb90 authored by Dallin Nickel (djn011)'s avatar Dallin Nickel (djn011)
Browse files

Now can bind any key to another, cannot bind multiple though

parent 924c674b
No related branches found
No related tags found
2 merge requests!45Prototype to Master for Milestone 5,!44Demo
package model;
import java.awt.*;
/**
* Testing program while the program is not yet completed so that we may test the system simulating keypresses.
*/
public class Action extends Hotkey implements InputEmulator{
/**
* Robot which simulates user key presses
*/
Robot robot;
/**
* Constructs an immutable hotkey.
* @param keyCode The virtual keycode of the hotkey.
* @param id The unique ID of the hotkey.
* @param modifier The modifier of the hotkey.
*/
public Action(int keyCode, int id, int modifier) throws AWTException {
super(keyCode, id, modifier);
this.robot = new Robot();
}
/**
* Sends a given key to be emulated.
* @param keyCode The virtual keycode of the key.
* @param release True if the key is to be a key release input.
*/
@Override
public void sendKey(int keyCode, boolean release) {
if (release) {
robot.keyPress(this.getKeyCode());
robot.keyRelease(this.getKeyCode());
}
}
}
......@@ -4,26 +4,30 @@ public class Binding {
/**
* Hotkey to be bound to an action
*/
Hotkey hotkey;
Hotkey hk1;
/**
* Action preformed when hotkey is pressed
*/
Action action;
Hotkey hk2;
/**
* The id of the hotkey and action pairing
*/
int id;
/**
* Constructor to bind the hotkey and the action together
* @param hotkey hotkey which is submitted
* @param action the action to be preformed when the hotkey is pressed
*
* @param hotkey1 hotkey which is submitted
* @param hotkey2 the action to be preformed when the hotkey is pressed
*/
public Binding(Hotkey hotkey, Action action){
this.hotkey = hotkey;
this.action = action;
this.id = hotkey.getID();
public Binding(Hotkey hotkey1, Hotkey hotkey2) {
this.hk1 = hotkey1;
this.hk2 = hotkey2;
}
public int getID() {
return this.hk1.getID();
}
public int getActionCode() {
return this.hk2.getKeyCode();
}
}
}
\ No newline at end of file
package model;
import ui.MainScreen;
import java.util.ArrayList;
import java.util.List;
public class Demo implements Runnable {
int id = 0;
int id;
boolean stop = false;
ArrayList<Binding> list = MainScreen.list;
public Demo() {
......@@ -10,11 +16,13 @@ public class Demo implements Runnable {
public void run() {
while (!stop) {
if (OSInterface.getInstance().wasPressed(id)) {
OSInterface.getInstance().sendKey(0x70, false);
for (Binding binding : list) {
if (OSInterface.getInstance().wasPressed(binding.getID())) {
OSInterface.getInstance().sendKey(binding.getActionCode(), true);
}
}
}
}
}
public void stop() {
stop = true;
......
......@@ -5,10 +5,14 @@ import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import model.Binding;
import model.Hotkey;
import model.Modifier;
import model.OSInterface;
import java.util.ArrayList;
import java.util.List;
/**
* mainScreen is the main UI page for the program. All user functions start here.
*/
......@@ -17,6 +21,7 @@ public class MainScreen extends Pane {
Stage primaryStage = new Stage();
Scene mainScreenScene = new Scene(this, 800, 800);
int id = 0;
public static ArrayList<Binding> list = new ArrayList<>();
public MainScreen() {
......@@ -146,6 +151,9 @@ public class MainScreen extends Pane {
"-fx-pref-width: 100px; -fx-pref-height: 50px; -fx-text-align: center;");
save.setOnAction(e -> {
Hotkey newHotkey = new Hotkey(KBV.getKeyToBind(), id, Modifier.NONE.val());
Hotkey action = new Hotkey(KBV.getKeyAction(), id, Modifier.NONE.val());
Binding binding = new Binding(newHotkey, action);
list.add(binding);
id ++;
boolean register = OSInterface.getInstance().registerHotkey(newHotkey);
primaryStage.setScene(mainScreenScene);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment