# Key and keyCode flicker on release

**URL:** <https://discourse.processing.org/t/key-and-keycode-flicker-on-release/13960>\
**Category:** Coding Questions\
**Created:** [September 13, 2019, 7:16am UTC](https://discourse.processing.org/t/key-and-keycode-flicker-on-release/13960 "2019-09-13T07:16:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blosh](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@blosh](https://discourse.processing.org/u/blosh)\
**Post date:** [September 13, 2019, 7:16am UTC](https://discourse.processing.org/t/key-and-keycode-flicker-on-release/13960/1 "2019-09-13T07:16:49Z")

</div>

When pressing two keys at the same time, then releasing one, processing registers that key as being pressed for a couple of frames.  
To replicate this issue, use this code:

```auto
void setup() {
  size(400,400);
  fill(0);
  textSize(64);
  textAlign(CENTER);
}

void draw() {
  background(255);
  text(key, 200, 100);
  text(keyCode, 200, 200);
  text(str(keyPressed), 200, 300);
}

```

Firstly, press down on ‘q’ (or any key) and hold. Then, press down on ‘w’ (or any other key) and hold down. Release ‘q’ while still holding ‘w’ and you should see that it registers ‘q’ as being pressed for a short moment.

Is there anyway to get around this?

---

<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:** [September 13, 2019, 8:07am UTC](https://discourse.processing.org/t/key-and-keycode-flicker-on-release/13960/2 "2019-09-13T08:07:36Z")

</div>

for detect several keys pressed ?parallel?  
use the

- keyPressed()
- keyReleased()

structure  
and some memory

```auto
boolean[] keysb=new boolean[4];
char[] keyss={'q','w','e','r'}; // key list to be detected parallel
String t ="";

void setup() {
  size(400, 400);
  fill(0);
  textSize(64);
  textAlign(CENTER);
  print("use keys:");
  for ( int i=0;i<4;i++) print("["+keyss[i]+"]");
  println();
}

void draw() {
  background(255);
  write();
}

void write() {
  t="";
  for ( int i=0;i<4;i++) if ( keysb[i] ) t+=keyss[i];
  if ( t.equals("") ) t="_";
  text(t, 200, 100);
}

void keyPressed() {
  for ( int i=0;i<4;i++) if ( key==keyss[i] ) keysb[i]=true;
}

void keyReleased() {
  for ( int i=0;i<4;i++) if ( key==keyss[i] ) keysb[i]=false;
}

```

like for games what use 4 keys ( walk directions ) but need to walk diagonal too.

> **Runner version**
>
> ```auto
> int[] keysb={0,0,0,0}; // pressed key memory, NOW INT
> char[] keyss={'q','w','e','r'}; // key list to be detected parallel
> String t ="";
> int x, y, spd=3,size=5;
> 
> void setup() {
> size(400, 400);
> fill(0);
> textSize(64);
> textAlign(CENTER);
> print("use keys:");
> for ( int i=0;i<4;i++) print("["+keyss[i]+"]");
> println();
> }
> 
> void draw() {
> background(255);
> write();
> move();
> }
> 
> void write() {
> t="";
> for ( int i=0;i<4;i++) if ( keysb[i]==1 ) t+=keyss[i];
> if ( t.equals("") ) t="_";
> text(t, 200, 100);
> }
> 
> void move() {
> x = constrain(x += spd*( keysb[3]-keysb[2] ), 0, width-size);
> y = constrain(y += spd*( keysb[1]-keysb[0] ), 0, height-size);
> square(x, y, size);
> }
> 
> void keyPressed() {
> for ( int i=0;i<4;i++) if ( key==keyss[i] ) keysb[i]=1;
> }
> 
> void keyReleased() {
> for ( int i=0;i<4;i++) if ( key==keyss[i] ) keysb[i]=0;
> }
> 
> ```
