You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -432,16 +432,18 @@ In p5.js 2.0, instead of having separate methods for mouse and touch, we now use
432
432
433
433
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.
434
434
435
-
## …using mouseButton
435
+
## …using mouseButton events:
436
436
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).
438
440
439
441
```js
440
442
functionsetup() {
441
443
createCanvas(100, 100);
442
444
443
445
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."
445
447
);
446
448
}
447
449
```
@@ -453,6 +455,7 @@ function setup() {
453
455
```js
454
456
functiondraw() {
455
457
background(200);
458
+
fill(255, 50);
456
459
457
460
if (mouseIsPressed ===true) {
458
461
if (mouseButton ===LEFT) {
@@ -474,6 +477,7 @@ function draw() {
474
477
```js
475
478
functiondraw() {
476
479
background(200);
480
+
fill(255, 50);
477
481
478
482
if (mouseIsPressed ===true) {
479
483
if (mouseButton.left) {
@@ -492,17 +496,20 @@ function draw() {
492
496
</td></tr>
493
497
</table>
494
498
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
+
496
503
`keyCode` is still a `Number` system variable in 2.x.
497
504
```js
498
505
if (keyCode ===13) {
499
506
// Code to run if the enter key was pressed.
500
507
}
501
508
```
502
509
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
0 commit comments