Skip to content
Snippets Groups Projects
Commit ded817e8 authored by Dallin Nickel (djn011)'s avatar Dallin Nickel (djn011) Committed by NikolaBabic
Browse files

Created Binding class which binds a hotkey with an action

parent 6ea8debb
No related branches found
No related tags found
No related merge requests found
package model;
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
public class Action implements InputEmulator{
public class Action extends Hotkey implements InputEmulator{
/**
* Robot to simulate button presses
* Robot which simulates user key presses
*/
Robot robot;
/**
* Constructor to create a new robot to control key presses
* @throws AWTException
* 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() throws AWTException {
public Action(int keyCode, int id, Modifier modifier) throws AWTException {
super(keyCode, id, modifier);
this.robot = new Robot();
}
/**
......@@ -26,7 +27,9 @@ public class Action implements InputEmulator{
*/
@Override
public void sendKey(int keyCode, boolean release) {
robot.keyPress(keyCode);
robot.keyRelease(keyCode);
if (release) {
robot.keyPress(this.getKeyCode());
robot.keyRelease(this.getKeyCode());
}
}
}
package model;
public class Binding {
/**
* Hotkey to be bound to an action
*/
Hotkey hotkey;
/**
* Action preformed when hotkey is pressed
*/
Action action;
/**
* 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
*/
public Binding(Hotkey hotkey, Action action){
this.hotkey = hotkey;
this.action = action;
this.id = hotkey.getID();
}
}
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