paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.45k stars 1.22k forks source link

Bug when pressing multiple arrow keys #403

Closed samueller closed 10 years ago

samueller commented 10 years ago

This seems like a bug, it's certainly affecting my ability to teach game development with Paper.js. When you hold down left and right arrow keys at the same time, then paper.Key.isDown(key) will always return false even when you are holding down that key! Same thing happens when you hold down up and down arrow keys.

function onFrame(event) {
  if (paper.Key.isDown('a'))
    console.log('a was pressed');
}

Pressing 'a' outputs 'a was pressed' to the console. But holding down 2 opposite arrow keys and then 'a' outputs nothing.

This wouldn't seem like too big of a deal, who presses up and down at the same time along with other keys? But it's actually impossible to make a game that uses arrow keys for movement this way! What happens is you are moving left and right and sometimes you hit both at the same time as a natural course of movement. Then you try to jump or shoot while doing that and you can't!

lehni commented 10 years ago

What browser / system are you experiencing this on? I can't replicate on Chrome / OSX, so maybe this is a browser bug? Also, did you compare with what jQuery key events give you? If it's the same behavior, then it's most probably a browser limitation...

samueller commented 10 years ago

This is an issue on Mac OS X 10.9.1 under Chrome Version 32.0.1700.107 as well as Firefox version 27.0.1

lehni commented 10 years ago

I'm on OSX 10.9.1 and Chrome 32.0.1700.107 as well and can't reproduce this:

http://sketch.paperjs.org/#S/hc6xCsIwEAbgVzmyJEHJA+gqLo7SLUtIrxpa70KTWqT03Y3VpSD0tv/4+fgnQe6B4iCuLWZ/F3vhuf7kZiCfAxMwXfB14pEUPpGyhskSlPNMiTs0Hd+UbL8VkLCDpWbKRx8tzZYsra0qbkhV3HbOfZm9ckIDqugmpGWsdFLrP76D0SWIPaaEtfzRYn4D

(Make sure to click onto the canvas first)

samueller commented 10 years ago

The paperjs.org domain has not been resolving for me at all. I'm eager to see what the issue is.

lehni commented 10 years ago

Yeah there were DNS problems yesterday apparently. Should be fixed now!

On Feb 20, 2014, at 05:34 , Scott Mueller notifications@github.com wrote:

The paperjs.org domain has not been resolving for me at all. I'm eager to see what the issue is.

— Reply to this email directly or view it on GitHub.

samueller commented 10 years ago

paperjs.org and sketch.paperjs.org both still not resolving for me, I might have old cached entries.

lehni commented 10 years ago

Well I haven't changed anything in the code, but I can't reproduce your problem with the same software as you use.

samueller commented 10 years ago

Interesting issues with that demo. So if you hold down opposite arrow keys (up and down or left and right) then press the following keys (that I found so far): space, a different arrow key, tab and delete. Then the onKeyDown and onKeyUp callback functions are _not_ called. And Key.isDown('space') or any other key always returns false in the onFrame function even when it's pressed down.

However, if you hold down opposite arrow keys and press any other key than those I mentioned above, everything works fine. Key.isDown('a') works as expected and onKeyDown and onKeyUp functions are called.

Any way to get arrow keys and space working as expected? I could just have the kids not use space bar in their games, but it's the key every kid wants to use.

lehni commented 10 years ago

Could you compare with the interactive demo on the Keypress library website here?

http://dmauro.github.io/Keypress/

If you see the same behavior there then it's a limitation of the browser. If not then we have a bug!

samueller commented 10 years ago

The issue happens on Safari, Chrome and Firefox with that link. Is that the library used in paper.js? I know games that use the arrow keys in JavaScript where you can press 3 arrow keys at the same time.

lehni commented 10 years ago

No we don't use that library. Could you point me to an example online where that is working correctly?

christophknoth commented 10 years ago

Not sure if this is still a thing in modern day keyboards but maybe its an interesting reference anyways http://www.microsoft.com/appliedsciences/antighostingexplained.mspx

What is the problem? "Ghosting" is the problem that some keyboard keys don't work when multiple keys are pressed simultaneously. The key presses that don't show up on the computer or seem to have disappeared are said to have been "ghosted". On most keyboards, even some that are explicitly marketed as "Anti-Ghosting," this happens with many three key combinations. Imagine playing your favorite video game and not being able to, say, run diagonally and fire your weapon at the same time (say pressing a, w, and g simultaneously). This is a result of the internal design of most existing keyboards, as will be explained below.

samueller commented 10 years ago

This issue is fixed for me in 0.9.17 :)