Use Key and [+] [-] as color sliders?

please try:
KEY PLUS PLUS

// possibly you know ( or have even tested ) my Mouse Wheel Plus Plus,
// a idea to multiplex the mouse wheel input by pressing keys
// so generating multi invisible sliders.

// now from here a other idea i want you to check out if that is a possible HMI concept:
String info = "Key Plus Plus \nfirst you press [r] or [g] or [b], next you press [+] or [-]";
// here use it on a color R G B example, but not limited to color, or only 3 "sliders"
// ( sure that has been done already somewhere, like all what we play here. )

// note: while with MWPP you must keep the key (r g b ) pressed and turn mousewheel,
// here do not keep the character keys pressed, use like [r] [+] [+] [g] [-]

int r=50, g=50, b=50;
char cmode = ' ';
color c;

//_______________________________________________ SETUP
void setup() {
  size(200, 200);
  colorMode(RGB, 100);
  c = color(r, g, b);
  println(info);
}

//_______________________________________________ DRAW
void draw() {
  background(c);
}

//_______________________________________________ OPERATION Key Plus Plus
void keyPressed() {
  int xdc,dc=5; //______________________________ color range 100 in steps of 5
  if ( key == 'r' || key == 'g' || key == 'b' ) cmode = key; 
  else if ( key == '+' || key == '-' ) {
    if ( key == '+' ) xdc = dc;
    else              xdc = -dc;
    if      ( cmode == 'r' ) r += xdc;
    else if ( cmode == 'g' ) g += xdc;
    else if ( cmode == 'b' ) b += xdc;
    r = constrain(r,0,100);
    g = constrain(g,0,100);
    b = constrain(b,0,100);
    c = color(r, g, b);
    println("cmode: "+cmode+", key:"+key+", c = color( "+r+" , "+g+" , "+b+" ); of RGB 100");
  }
  else cmode = ' '; //__________________________ reset cmode on any other key
}

for ref also old
MOUSE WHEEL PLUS PLUS

String info = "MouseWheelPlusPlus: press\n[r] red\n[g] green\n[b] blue\nand turn mousewheel";

int r=50, g=50, b=50;               // color RGB
color c;

//_______________________________________________ SETUP
void setup() {
  size(200, 200);
  colorMode(RGB, 100);
  c = color(r, g, b);
  println(info);
}

//_______________________________________________ DRAW
void draw() {                 
  background(c);
}

//_______________________________________________ OPERATION Mouse Wheel Plus Plus
void mouseWheel(MouseEvent event) {   // move mouse wheel
  float e = event.getCount();
  if ( keyPressed && key == 'r' )  r += e;
  if ( keyPressed && key == 'g' )  g += e;
  if ( keyPressed && key == 'b' )  b += e; 
  r = constrain(r, 0, 100);
  g = constrain(g, 0, 100);
  b = constrain(b, 0, 100);
  println("c = color( "+r+" , "+g+" , "+b+" ); of RGB 100");
  c = color(r, g, b);
}


thanks for testing and feedback.

1 Like

Interesting sketches, thanks for sharing. With Key++ I stumbled upon a problem, which I guess is caused because we have different keyboard layouts.

The - key works fine, but the + doesn’t. Probably because I also have to hold my shift button to type a +. Perhaps keycodes are a safer solution than using symbols?

1 Like

thanks for testing

ok, possible, that would not be of practical use, even if working…

i use the [+] [-] from a big keyboard, the https://en.wikipedia.org/wiki/Numeric_keypad

but also the use of the UP DOWN ARROW keys would fit good for this functionality

as the left hand would operate the [r][g][b]… keys
now add [w] for textSize ( just 3 more lines for a add slider… )

String info = "Key Plus Plus \nfirst you press [r] or [g] or [b], or key[w] next you press [UP] or [DOWN] arrow keys";

int r=50, g=50, b=50, w=10;
char cmode = ' ';
color c;

//_______________________________________________ SETUP
void setup() {
  size(200, 200);
  colorMode(RGB, 100);
  c = color(r, g, b);
  textSize(w);
  textAlign(CENTER,CENTER);
  println(info);
}

//_______________________________________________ DRAW
void draw() {
  background(c);
  text("KPP",width/2,height/2);
}

//_______________________________________________ OPERATION Key Plus Plus
void keyPressed() {
  int xdc,dc=5; //______________________________ color range 100 in steps of 5
  if ( key == 'r' || key == 'g' || key == 'b' || key == 'w' ) cmode = key; 
  else if ( keyCode == UP || keyCode == DOWN ) {
    if ( keyCode == UP ) xdc =  dc;
    else                 xdc = -dc;
    if      ( cmode == 'r' ) r += xdc;
    else if ( cmode == 'g' ) g += xdc;
    else if ( cmode == 'b' ) b += xdc;
    else if ( cmode == 'w' ) w += xdc;
    r = constrain(r,0,100);
    g = constrain(g,0,100);
    b = constrain(b,0,100);
    w = constrain(w,10,100);
    c = color(r, g, b);
    textSize(w);
    println("mode: "+cmode+", c = color( "+r+" , "+g+" , "+b+" ); of RGB 100, textSize("+w+")");
  }
  else cmode = ' '; //__________________________ reset cmode on any other key
}

Unfortunately my laptop doesn’t have a numeric keypad. All keyboards should have arrow keys though, perhaps that’s an easier fix

1 Like