Checking Whether a Key is Pressed - issue

35 views
Skip to first unread message

Dan Salmonsen

unread,
Jun 5, 2012, 7:25:59 PM6/5/12
to pap...@googlegroups.com
In this tutorial example, the script will not draw when mouse is move
for the first time while the 'a' key is pressed.

http://paperjs.org/tutorials/interaction/keyboard-interaction/#is-that-key-pressed

Is there a reason or work around for this?

Thanks,
Dan

Jonathan Puckey

unread,
Jun 6, 2012, 6:07:37 AM6/6/12
to pap...@googlegroups.com
The solution would be to check if the path has only 1 segment and then add an extra one if it has:

var path;
function onMouseDown(event) {
path = new Path();
path.strokeColor = 'black';
path.add(event.point);
}

function onMouseDrag(event) {
if(Key.isDown('a')) {
if (path.segments.length == 1)
path.add(event.point);
// If the 'a' key is down, change the point of
// the last segment to the position of the mouse:
path.lastSegment.point = event.point;
} else {
// If the a key is not down, add a segment
// to the path at the position of the mouse:
path.add(event.point);

dansalmo

unread,
Jun 9, 2012, 12:34:50 AM6/9/12
to Paper.js
Jonathan,

Thank you for the explanation and working example.
> >http://paperjs.org/tutorials/interaction/keyboard-interaction/#is-tha...
Reply all
Reply to author
Forward
0 new messages