# P5.js - Mouse and keys stuck

**URL:** <https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556>\
**Category:** Coding Questions\
**Created:** [November 15, 2018, 9:34am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556 "2018-11-15T09:34:54Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 15, 2018, 9:34am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/1 "2018-11-15T09:34:54Z")

</div>

Hi,

I’ve been experimenting with p5.js for a bit, and I’ve noticed that the mouse and key functions sometimes get stuck.

The problem is caused for me when you right-click, or hold a key, then right-click. (In the sketch below)

Here is an example of the problem I’m facing:  
[editor.p5js.org/SarahJ/sketches/ByNHnh56X](http://editor.p5js.org/SarahJ/sketches/ByNHnh56X)

Thanks!

---

<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:** [November 15, 2018, 9:47am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/2 "2018-11-15T09:47:19Z")

</div>

did you experiment with the

```auto
  // prevent default
  return false;

```

i see  
[https://p5js.org/reference/#/p5/mousePressed](https://p5js.org/reference/#/p5/mousePressed)

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 15, 2018, 10:00am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/3 "2018-11-15T10:00:52Z")

</div>

Thanks for the tip - I’ve added it to the program. Unfortunately, the problem still occurs with the same reasons as before. I’m using macOS Sierra - Could that be the cause?

---

<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:** [November 15, 2018, 10:02am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/4 "2018-11-15T10:02:59Z")

</div>

no idea about OS,  
also possibly a browser problem,  
but to separate the problem from the  
p5.js site environment  
try do a download and ftp upload to a server.

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 15, 2018, 10:06am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/5 "2018-11-15T10:06:11Z")

</div>

Thanks - I’ll try that.

---

<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:** [November 15, 2018, 10:10am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/6 "2018-11-15T10:10:02Z")

</div>

p.s. your latest code after add that “tip” also  
for the keyboard, i see now under win7 / firefox /  
that the keyboard is not working at all, ( [space] gives a jump because it seems to force firefox to reload the page )  
mouse press OK

//\_\_\_\_\_\_\_\_\_\_\_  
the resulting thing what is send to the browser is as i understand a .png,  
and all browser open on mouse right click the image save menu,  
possibly you should do like  
mousePressed  
if mouseButton == LEFT … move true;

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 15, 2018, 10:30am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/7 "2018-11-15T10:30:50Z")

</div>

That’s what I was considering too, but I wanted to know first if it was a bug or something fixable.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 15, 2018, 12:54pm UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/8 "2018-11-15T12:54:36Z")

</div>

> <https://github.com/processing/p5.js/issues/3317>

---

<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:** [November 15, 2018, 1:29pm UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/9 "2018-11-15T13:29:18Z")

</div>

on  
win7 SP0 : ( 32bit )  
firefox 63. || chrome 70.  
using  
[https://editor.p5js.org/](https://editor.p5js.org/) || Processing 3.4 mode p5.js

> use right mouse button:  
> press and hold and release

i see in console || inspect console

```auto
mouse pressed 
right-click 
mouse released 
right-click 

```

despite the upcoming context menu

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 15, 2018, 10:26pm UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/10 "2018-11-15T22:26:08Z")

</div>

Weird… Must be a Mac bug then. I’m going to try using a mouse and see what happens.

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 16, 2018, 6:48am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/11 "2018-11-16T06:48:38Z")

</div>

I’ve figured out how to fix it, it seems when you right-click in Chrome it opens up a context menu (which takes away focus from the browser), so if you disable that it should work. You can disable it by putting:  
`oncontextmenu=" event.preventDefault();` in sketch.js  
or  
`<body oncontextmenu="return false;">` in index.html

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 9:37am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/12 "2018-11-16T09:37:21Z")

</div>

> [@Sarah](#):
>
> `oncontextmenu=" event.preventDefault();`

Is that a string assignment or some typo? 🤔

Maybe this 1 should work too? 🤷‍♂️  
`oncontextmenu = () => false;`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 16, 2018, 10:02am UTC](https://discourse.processing.org/t/p5-js-mouse-and-keys-stuck/5556/13 "2018-11-16T10:02:19Z")

</div>

> **[GlobalEventHandlers.oncontextmenu](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oncontextmenu#Example)**
>
> The oncontextmenu property of the GlobalEventHandlers mixin is an EventHandler that processes contextmenu events.
