Skip to content

Commit bea9f9a

Browse files
author
lauren mccarthy
committed
Merge branch 'crhallberg-keyreleased'
2 parents 52db133 + 96c08e4 commit bea9f9a

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ p5.js is a new interpretation, not an emulation or port, and it is in active dev
99

1010
##p5.js library
1111

12-
You can [download here](http://p5js.org/get-started) or use `lib/p5.js` for the less stable, newest version.
12+
You can [download here](http://p5js.org/download) or use `lib/p5.js` for the less stable, newest version.
1313

1414
##Documentation
1515

@@ -31,6 +31,7 @@ This project developed out of a Fellowship with the Processing Foundation explor
3131

3232

3333
##Development
34+
3435
See the [contribute section](http://p5js.org/contribute) to get started and check out the [development](https://github.com/lmccart/p5.js/wiki/Development) wiki page for details.
3536

3637

lib/p5.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var core = function (require, shim, constants) {
8989
var constants = constants;
9090
var p5 = function (sketch, node) {
9191
this._setupDone = false;
92-
this._pixelDensity =2;// window.devicePixelRatio || 1;
92+
this._pixelDensity = window.devicePixelRatio || 1;
9393
this._startTime = new Date().getTime();
9494
this._userNode = node;
9595
this._curElement = null;
@@ -1020,7 +1020,7 @@ var p5Image = function (require, core, filters) {
10201020
var currBlend = this.drawingContext.globalCompositeOperation;
10211021
var scaleFactor = 1;
10221022
if (p5Image instanceof p5.Graphics) {
1023-
scaleFactor = p5Image._pixelDensity;
1023+
scaleFactor = p5Image._pInst._pixelDensity;
10241024
}
10251025
var copyArgs = [
10261026
p5Image,
@@ -2976,6 +2976,12 @@ var inputkeyboard = function (require, core) {
29762976
var keyReleased = this.keyReleased || window.keyReleased;
29772977
this._setProperty('isKeyPressed', false);
29782978
this._setProperty('keyIsPressed', false);
2979+
var key = String.fromCharCode(e.which);
2980+
if (!key) {
2981+
key = e.which;
2982+
}
2983+
this._setProperty('key', key);
2984+
this._setProperty('keyCode', e.which);
29792985
if (typeof keyReleased === 'function') {
29802986
keyReleased(e);
29812987
}

lib/p5.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/input/keyboard.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ define(function (require) {
99
'use strict';
1010

1111
var p5 = require('core');
12-
12+
1313
/**
1414
* The boolean system variable keyIsPressed is true if any key is pressed
1515
* and false if no keys are pressed.
1616
*
17-
* @property keyIsPressed
17+
* @property keyIsPressed
1818
* @example
1919
* <div>
2020
* <code>
@@ -32,7 +32,7 @@ define(function (require) {
3232
*/
3333
p5.prototype.isKeyPressed = false;
3434
p5.prototype.keyIsPressed = false; // khan
35-
35+
3636
/**
3737
* The system variable key always contains the value of the most recent
3838
* key on the keyboard that was typed. To get the proper capitalization, it
@@ -54,21 +54,21 @@ define(function (require) {
5454

5555
/**
5656
* The keyPressed() function is called once every time a key is pressed. The
57-
* keyCode for the key that was pressed is stored in the keyCode variable.
57+
* keyCode for the key that was pressed is stored in the keyCode variable.
5858
* <br><br>
5959
* For non-ASCII keys, use the keyCode variable. You can check if the keyCode
60-
* equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL,
60+
* equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL,
6161
* OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.
6262
* <br><br>
6363
* For ASCII keys that was pressed is stored in the key variable. However, it
6464
* does not distinguish between uppercase and lowercase. For this reason, it
6565
* is recommended to use keyTyped() to read the key variable, in which the
6666
* case of the variable will be distinguished.
6767
* <br><br>
68-
* Because of how operating systems handle key repeats, holding down a key
69-
* may cause multiple calls to keyTyped() (and keyReleased() as well). The
70-
* rate of repeat is set by the operating system and how each computer is
71-
* configured.
68+
* Because of how operating systems handle key repeats, holding down a key
69+
* may cause multiple calls to keyTyped() (and keyReleased() as well). The
70+
* rate of repeat is set by the operating system and how each computer is
71+
* configured.
7272
*
7373
* @method keyPressed
7474
* @example
@@ -146,6 +146,12 @@ define(function (require) {
146146
var keyReleased = this.keyReleased || window.keyReleased;
147147
this._setProperty('isKeyPressed', false);
148148
this._setProperty('keyIsPressed', false);
149+
var key = String.fromCharCode(e.which);
150+
if (!key) {
151+
key = e.which;
152+
}
153+
this._setProperty('key', key);
154+
this._setProperty('keyCode', e.which);
149155
if (typeof keyReleased === 'function') {
150156
keyReleased(e);
151157
}
@@ -156,10 +162,10 @@ define(function (require) {
156162
* action keys such as Ctrl, Shift, and Alt are ignored. The most recent
157163
* key pressed will be stored in the key variable.
158164
* <br><br>
159-
* Because of how operating systems handle key repeats, holding down a key
160-
* will cause multiple calls to keyTyped(), the rate is set by the operating
161-
* system and how each computer is configured.
162-
*
165+
* Because of how operating systems handle key repeats, holding down a key
166+
* will cause multiple calls to keyTyped(), the rate is set by the operating
167+
* system and how each computer is configured.
168+
*
163169
* @method keyTyped
164170
* @example
165171
* <div>

src/rendering/rendering.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ define(function(require) {
1212
/**
1313
* Creates a canvas element in the document, and sets the dimensions of it
1414
* in pixels. This method should be called only once at the start of setup.
15-
* <br>
15+
* Calling createCanvas more than once in a sketch will result in very
16+
* unpredicable behavior. If you want more more than one drawing canvas
17+
* you could use createGraphics (hidden by default but it can be shown).<br>
1618
* The system variables width and height are set by the parameters passed
1719
* to this function. If createCanvas() is not used, the window will be
1820
* given a default size of 100x100 pixels.

0 commit comments

Comments
 (0)