Jump to content

keyborder events


Recommended Posts

Add the event to the canvas element instead of the document.

$("#world").html(this.renderer.view)$("#world").bind( "keydown", function( event ) {	event.preventDefault();	console.log(event);});$('#world').focus();

But, its not help, no keyboard event, when i press

Link to comment
Share on other sites

I solved the problem using this method

	this.renderer.view.setAttribute("id", "worldCanvas");        $("#world").html(this.renderer.view);         var lastDownTarget, canvas;		canvas = document.getElementById('worldCanvas');		lastDownTarget = canvas;		document.addEventListener('mousedown', function(event) {			lastDownTarget = event.target;		}, false);			document.addEventListener('keydown', function(event) {			if(lastDownTarget == canvas) {                                event.preventDefault();                                event.stopPropagation();				wi.doKeyDown(event);			}		}, false);
Link to comment
Share on other sites

Holding a variable just to check focus sounds like a terrible idea, the `tabindex` method would surely be more intuitive (although still a hack, but, whats a hack between friends anyway?)? I've thrown it into a plunk and it works fine, I havent checked browser compatibility but I'd imagine it works everywhere (I'd say that mobile could cause a problem, but you're not using keyboard interface there anyways, actually, given new tablets this could be viable, particularly in the near future).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...