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

**URL:** https://discourse.processing.org/t/use-key-and-as-color-sliders/16397
**Category:** Gallery
**Created:** [December 14, 2019, 1:38pm UTC](https://discourse.processing.org/t/use-key-and-as-color-sliders/16397 "2019-12-14T13:38:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 14, 2019, 1:38pm UTC](https://discourse.processing.org/t/use-key-and-as-color-sliders/16397/1 "2019-12-14T13:38:15Z")

</div>

please try:  
KEY PLUS PLUS

```auto
// 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

```auto
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.

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [December 19, 2019, 11:37am UTC](https://discourse.processing.org/t/use-key-and-as-color-sliders/16397/2 "2019-12-19T11:37:29Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 19, 2019, 11:43am UTC](https://discourse.processing.org/t/use-key-and-as-color-sliders/16397/3 "2019-12-19T11:43:56Z")

</div>

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](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… )

```auto
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
}

```

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [December 19, 2019, 11:50am UTC](https://discourse.processing.org/t/use-key-and-as-color-sliders/16397/4 "2019-12-19T11:50:19Z")

</div>

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