Skip to content

Commit b8fbd0d

Browse files
committed
keydown and keyup events now fire for every possible key, no matter if they exist in the KeyCodes list or not.
1 parent 17e7dde commit b8fbd0d

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ There is also the `stopPropagation()` function. This works in the same way as `s
3333

3434
All the above also works for `keyup` events.
3535

36+
New in 3.16 is the ability to receive a global `keydown` or `keyup` event from any key on the keyboard. Previously, it would only emit the event if it came from one of the keys listed in the KeyCodes file. Now, those global events will fire for any key, regardless of location.
37+
3638
#### Keyboard Captures
3739

3840
Key capturing is the way in which you stop a keyboard DOM event from activating anything else in the browser by calling `preventDefault` on it. For example, in tall web pages, pressing the SPACE BAR causes the page to scroll down. Obviously, if this is also the fire or jump button in your game, you don't want this to happen. So the key needs to be 'captured' to prevent it. Equally, you may wish to also capture the arrow keys, for similar reasons. Key capturing is done on a global level. If you set-up the capture of a key in one Scene, it will be captured globally across the whole game.

src/input/keyboard/KeyboardManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ var KeyboardManager = new Class({
188188
// Do nothing if event already handled
189189
return;
190190
}
191-
191+
192192
_this.queue.push(event);
193193

194194
var modified = (event.altKey || event.ctrlKey || event.shiftKey || event.metaKey);

src/input/keyboard/KeyboardPlugin.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,13 @@ var KeyboardPlugin = new Class({
718718
key.onDown(event);
719719
}
720720

721-
if (!event.cancelled && KeyMap[code] && (!key || !repeat))
721+
if (!event.cancelled && (!key || !repeat))
722722
{
723723
// keydown_code event
724-
this.emit('keydown_' + KeyMap[code], event);
724+
if (KeyMap[code])
725+
{
726+
this.emit('keydown_' + KeyMap[code], event);
727+
}
725728

726729
if (!event.cancelled)
727730
{
@@ -738,10 +741,13 @@ var KeyboardPlugin = new Class({
738741
key.onUp(event);
739742
}
740743

741-
if (!event.cancelled && KeyMap[code])
744+
if (!event.cancelled)
742745
{
743746
// keyup_code event
744-
this.emit('keyup_' + KeyMap[code], event);
747+
if (KeyMap[code])
748+
{
749+
this.emit('keyup_' + KeyMap[code], event);
750+
}
745751

746752
if (!event.cancelled)
747753
{

0 commit comments

Comments
 (0)