Hi, I'm looking to create macros for the user so that the user can type their desired commands (as an alternative to clicking on-screen buttons) so that 'the user can have a more streamlined experience'
Macros:
0-9 (no problems here)
operators (no problems here)
Holding CTRL and typing in (up to) 4 characters, eg CTRL+root
code so far (don't mind the multitude of multi-line comments, those are notes to myself):
the contents of the constructor can be ignored, (i was a little indecisive between act and constructor) but the constructor contains the full list of all the macros
I have explained why 'checkKeyPress' is an actor in the comments (first few lines)
Thanks
public class checkKeyPress extends Actor
{
//This class was intended to be a method. However, due to the...
//...'method' being designed to suit multiple worlds, it was...
//...decided that checkKeyPress should be a publicly-accessible...
//...actor, to simplify and shorten code length and increase...
//...coding efficiency and code simplicity.
//some code may be externally sourced.
//Credit: Greenfoot Discussions,danpost, 2011
//Name of post: "Greenfoot.isKeyDown(any) ???"
private String keyPress;
private boolean ctrlHeld;
private String returnValue;
public final String numbers = "0123456789";
public final String symbols = "!^*x()+-=|./";
public String txtString = "";
Button buttonClass = new Button();
public checkKeyPress(){
/**numbers*/
/** +-/x=. */
/** | CTRLroot ^ CTRLfrac CTRLsincostan CTRLans () ! */
/** CTRLs CTRLa CTRLc CTRLm backspace */
}
/**
* Act - do whatever the checkKeyPress wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("ctrl")){
ctrlHeld = true;
}
else{
ctrlHeld = false;
}
/**move this code to a separate method because different worlds have different input*/
keyPress = Greenfoot.getKey();
if (keyPress == null) { return; }
if (! ctrlHeld){
if (keyPress == "backspace") /**change == to .equals("") for each*/
{
/**Code for when 'backspace' is pressed*/
}
/**for the following if statements, call checkkeypress in 'buttonClass'*/
if (numbers.contains(keyPress)){/***/}
if (symbols.contains(keyPress)){/***/} /** '*' and 'x' both mean multiply*/
}
if (ctrlHeld){
//code here...
}
}
