Createjs keyboard input

972 views
Skip to first unread message

Zanollo

unread,
Sep 15, 2015, 6:23:03 PM9/15/15
to Haxe
Hi, I can't figure out how I'm supposed to check for keyboard input while targeting js (using createjs for Haxe) .

I know that in js I can use "this.document.onkeydown = handlerFunction... " but can't find a way to do it on Haxe.

I read that something like "stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);" should work buuut KeyboardEvent doesn't have the KEY_DOWN property... at least not in Haxe3

Sorry if there's a similar question (couldn't find one) and sorry if it's a very simple/easy/boring question :)

Thanks in advance for the answers

Bruno Santos

unread,
Sep 15, 2015, 6:33:20 PM9/15/15
to Haxe

Try:

var something = new js.html.Document();
something.onkeydown = function(e){}.

The addEventListener is probably from nme or openfl.


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Philippe Elsass

unread,
Sep 16, 2015, 4:46:25 AM9/16/15
to Haxe
new Document really???

JS --> Haxe
window --> js.Browser.window
document --> js.Browser.document

Philippe
--
Philippe

Bruno Santos

unread,
Sep 16, 2015, 5:06:50 AM9/16/15
to Haxe

:) not that it excuses me, but it was the first thing I got when I searched for haxe js document ^_^

Rob Fell

unread,
Sep 16, 2015, 11:01:24 AM9/16/15
to Haxe
The solution isn't anything CreateJS or Haxe specific.  From awe6 CreateJS InputKeyboard:

var document = js.Browser.document; // must be linked to Browser
document.addEventListener( "keydown", _onKeyDown );
document.addEventListener( "keyup", _onKeyUp );

Also, consider scenarios where content is contained within an IFrame (common for HTML5 rich media, games etc), and the document will not have focus by default.
js.Browser.window.focus() on mousedown & touchstart is a useful addition for that.

Zanollo

unread,
Sep 17, 2015, 11:33:47 AM9/17/15
to Haxe
Thanks, I'll try that!
Reply all
Reply to author
Forward
0 new messages