# Lost keyPressed events

**URL:** https://discourse.processing.org/t/lost-keypressed-events/22903
**Category:** Processing
**Created:** [July 29, 2020, 12:17pm UTC](https://discourse.processing.org/t/lost-keypressed-events/22903 "2020-07-29T12:17:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![marek](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@marek](https://discourse.processing.org/u/marek)
#### Post date: [July 29, 2020, 12:17pm UTC](https://discourse.processing.org/t/lost-keypressed-events/22903/1 "2020-07-29T12:17:06Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I’m using the SHIFT and ALT keys as modifiers on mouse operations, but seem to be losing keyPressed events on the ALT key. Simple code example below. After hitting the ALT key a few dozen times, the ‘down’ count end up much less (about half) than the ‘up’ count.

The problem only seems to occur with the default JAVA2D renderer. P2D seems OK, but has other issues for me.

Any help much appreciated.

```auto

int sD, sU, aD, aU;

void setup() {
  size(400, 200);
  textSize(24);
}

void draw() {
  background(0);
  text(sU, 40, 40);
  text(sD, 40, 80);
  text(aU, 120, 40);
  text(aD, 120, 80);
}

void keyPressed() {
  if (key == CODED) {
    switch (keyCode) {
      case SHIFT: sD++; break;
      case ALT : aD++; break;
      default:
    }
  }
}

void keyReleased() {
  if (key == CODED) {
    switch (keyCode) {
      case SHIFT: sU++; break;
      case ALT: aU++; break;
      default:
    }
  }  
}

```

---

<div class="post-metadata">

### Author: ![marek](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@marek](https://discourse.processing.org/u/marek)
#### Post date: [July 29, 2020, 12:24pm UTC](https://discourse.processing.org/t/lost-keypressed-events/22903/2 "2020-07-29T12:24:08Z")

</div>

Oh, and I’m running Processing 3.5.4, Java 8 Update 161, Windows 10.

---

<div class="post-metadata">

### Author: ![marek](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@marek](https://discourse.processing.org/u/marek)
#### Post date: [July 29, 2020, 1:40pm UTC](https://discourse.processing.org/t/lost-keypressed-events/22903/3 "2020-07-29T13:40:34Z")

</div>

OK, another symptom…  
If I do a mouse click in the sketch window before each ALT key press, none of them get missed. It’s almost as though something in Processing gets confused about where the focus is - but just for ALT?

---

<div class="post-metadata">

### Author: ![marek](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@marek](https://discourse.processing.org/u/marek)
#### Post date: [July 29, 2020, 8:52pm UTC](https://discourse.processing.org/t/lost-keypressed-events/22903/4 "2020-07-29T20:52:15Z")

</div>

Hmm, looks like ALT toggles some boolean state in Processing/JAVA2D which when set blocks SHIFT, CTRL and ALT KeyEvents from reaching the sketch. A second ALT or a mouse click on the sketch window unblocks it.  
Anyone have any ideas as to what’s going on? Or even better, how to prevent it?
