# Use of "F1" KEY in p5.js

**URL:** <https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055>\
**Category:** Coding Questions\
**Created:** [February 8, 2022, 11:41pm UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055 "2022-02-08T23:41:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolembeek](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@Rolembeek](https://discourse.processing.org/u/Rolembeek)\
**Post date:** [February 8, 2022, 11:41pm UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055/1 "2022-02-08T23:41:33Z")

</div>

Hi all,

In my program I use the “h” key to bring up a kind of “Help Menu”. This works very well but I would like to replace it by a more “standard” use of the “F1” key (keyCode = 112). Whenever I use the F1 key the “normal” Chrome help page is opened …  
if (keyIsDown(112)) {  
// F1 Key  
helpON = true;  
}  
This doesn’t work the way I want disappointed: Any other possibility ?  
THNX  
Roland

---

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [February 9, 2022, 9:41am UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055/2 "2022-02-09T09:41:30Z")

</div>

This may be an issue with your web browser or operating system. It works fine for me in Chromium on MacOS (pressing F1 turns the background black instead of gray):

https://editor.p5js.org/Kumu-Paul/full/R-6Soy3MV

---

<div class="post-metadata">

**Author:** ![Rolembeek](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@Rolembeek](https://discourse.processing.org/u/Rolembeek)\
**Post date:** [February 9, 2022, 10:58pm UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055/3 "2022-02-09T22:58:20Z")

</div>

I’m using Win10 and tested your code on Chrome and Edge. Both same result : showing result (text) in code window but also performing “unwanted” tasks as opening ‘help’ (F1), search (F3), reload page (F5), navigation keys ? (F7), full screen (F11 → acceptable) and page source (F12). I think I’m overlooking a global setting somewhere … 🙁.

Thanks for your response anyway !

---

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [February 9, 2022, 11:45pm UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055/4 "2022-02-09T23:45:39Z")

</div>

I don’t have easy access to a windows machine to test this, but I updated the code slightly to prevent the default action associated with each keyboard event:

```javascript
function keyPressed(e) {
  e.preventDefault();
  pushEvent('keyPressed', e);
  redraw();
  return false;
}

```

On my system this prevents Browser/OS level actions that would normally be triggered (for example Command+P on my system would normally trigger the browser’s print function, but this sketch prevents that). Note that the sketch window needs to have focus for this to work.

---

<div class="post-metadata">

**Author:** ![Rolembeek](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@Rolembeek](https://discourse.processing.org/u/Rolembeek)\
**Post date:** [February 10, 2022, 2:39pm UTC](https://discourse.processing.org/t/use-of-f1-key-in-p5-js/35055/5 "2022-02-10T14:39:39Z")

</div>

YES ! 😁 This is working. Will need a lot of editing of my sketch as I use “keyIsDown”, “keyTyped”, keyIsPressed … Probably it is a good reason to review the whole put-up of the code as now it is the result of building always on top of previous versions. Good occasion to simplify a lot !

Thanks again for your help !
