Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06649d8

Browse files
authored
Update mouseButton events as per requested
1 parent 288af23 commit 06649d8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,18 @@ In p5.js 2.0, instead of having separate methods for mouse and touch, we now use
432432

433433
All of the above usages in p5.js 1.x remain available with the [data.js](https://github.com/processing/p5.js-compatibility/blob/main/src/data.js) compatibility add-on library.
434434

435-
## …using mouseButton
435+
## …using mouseButton events:
436436

437-
In 2.X, the `mouseButton` is now an object with props: `left`, `right` and `center`, which are booleans indicating whether each button has been pressed respectively.
437+
In 1.X, where the `mouseButton` was a single variable that could have values `left`, `right` and `center`, we cannot detect if the `left` and `right` button have been pressed together.
438+
In 2.X, the `mouseButton` is now an object with properties: `left`, `right` and `center`, which are booleans indicating whether each button has been pressed respectively.
439+
This means that we can now detect if multiple buttons are pressed together (like if the `left` and `right` button are pressed together).
438440

439441
```js
440442
function setup() {
441443
createCanvas(100, 100);
442444

443445
describe(
444-
"A gray square. Different shapes appear at its center depending on the mouse button that's clicked."
446+
"A gray square. Different shapes appear at its center depending on the mouse button that's pressed."
445447
);
446448
}
447449
```
@@ -453,6 +455,7 @@ function setup() {
453455
```js
454456
function draw() {
455457
background(200);
458+
fill(255, 50);
456459

457460
if (mouseIsPressed === true) {
458461
if (mouseButton === LEFT) {
@@ -474,6 +477,7 @@ function draw() {
474477
```js
475478
function draw() {
476479
background(200);
480+
fill(255, 50);
477481

478482
if (mouseIsPressed === true) {
479483
if (mouseButton.left) {
@@ -492,17 +496,20 @@ function draw() {
492496
</td></tr>
493497
</table>
494498

495-
## …using keyCode
499+
Notice that when you press multiple buttons at the same time, multiple shapes can be obtained.
500+
501+
## …using keyCode events:
502+
496503
`keyCode` is still a `Number` system variable in 2.x.
497504
```js
498505
if (keyCode === 13) {
499506
// Code to run if the enter key was pressed.
500507
}
501508
```
502509

503-
However, system variables like "ENTER" cannot be used like in 1.x, for example:
510+
In 1.x system variables could be used using keyCode
504511
```js
505-
if (keyCode === ENTER) {
512+
if (keyCode === "ENTER") {
506513
// Code to run if the enter key was pressed.
507514
}
508515
```

0 commit comments

Comments
 (0)