# Picture to load when a specific key isn’t pressed

**URL:** https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941
**Category:** Coding Questions
**Created:** [October 28, 2018, 10:05am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941 "2018-10-28T10:05:19Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)
#### Post date: [October 28, 2018, 10:05am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/1 "2018-10-28T10:05:19Z")

</div>

Hi I’m making a game and I need some help with a true/false line. I need picture to load when a specific key isn’t pressed (the key is ENTER).

---

<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: [October 28, 2018, 10:29am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/2 "2018-10-28T10:29:16Z")

</div>

your inverted logic is not fully clear,  
but the inverted function of keyPressed would be keyReleased  
like in " is not pressed any more "  
somehow i doubt that is what you want.

also you possibly want toggle something at ENTER Released??

```auto
boolean my_stat = true;
void setup() {}
void draw() {}
void keyReleased(){
if ( keyCode == ENTER ) { my_stat = !my_stat; println("my_stat: "+my_stat);} }

```

---

<div class="post-metadata">

### Author: ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)
#### Post date: [October 28, 2018, 11:00am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/3 "2018-10-28T11:00:09Z")

</div>

here’s an example

```auto
void draw() {
  if (!keyPressed) {
    if (key == 'b' || key == 'B') {
      fill(0);
    }
  } else {
    fill(255);
  }
  rect(25, 25, 50, 50);
}

```

the square should be black when b isn’t pressed but it is white in the start for some reason. it is important “!” is used in this case

---

<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: [October 28, 2018, 11:01am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/4 "2018-10-28T11:01:41Z")

</div>

where you detect the operation of the ENTER key?

---

<div class="post-metadata">

### Author: ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)
#### Post date: [October 28, 2018, 11:03am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/5 "2018-10-28T11:03:46Z")

</div>

just Imagine b is ENTER in this case.

---

<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: [October 28, 2018, 11:07am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/6 "2018-10-28T11:07:09Z")

</div>

if you want debug some code it helps to use  
println("something: "+something);

---

<div class="post-metadata">

### Author: ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)
#### Post date: [October 28, 2018, 11:09am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/7 "2018-10-28T11:09:16Z")

</div>

i can’t see how that’s gonna help me.

---

<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: [October 28, 2018, 11:18am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/8 "2018-10-28T11:18:19Z")

</div>

i used the example  
and changed to !keyPressed and it works here,  
( like at the second time )  
also shift key is a problem  
anyhow you could never use in combination with other key detect

```auto
// Click on the window to give it focus,
// and press the 'b' key.

void draw() {
  if (!keyPressed) {
    if (key == 'b' || key == 'B') {
      fill(0);
    }
  } else {
    fill(255);
  }
  rect(25, 25, 50, 50);
}

```

so just not do it that way.

---

<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: [October 28, 2018, 11:22am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/9 "2018-10-28T11:22:16Z")

</div>

test

```auto
// Click on the window to give it focus,
// and press the 'B' key.
int k = 0;

void draw() {
  if (!keyPressed) {
    if (key == 'b' || key == 'B') {
      k++;
      println("k: "+k+" key: "+key);
      fill(0);
    }
  } else {
    fill(255);
  }
  rect(25, 25, 50, 50);
}

```

to actually see what you are doing

---

<div class="post-metadata">

### Author: ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)
#### Post date: [October 28, 2018, 11:23am UTC](https://discourse.processing.org/t/picture-to-load-when-a-specific-key-isn-t-pressed/4941/10 "2018-10-28T11:23:43Z")

</div>

ty i think i have solved it
