Jump to content

Keyboard controls and the debug console


Recommended Posts

Hey there, its me again with two stupid questions  :unsure:


I looked for many examples on the web to understand how I can execute code when a key is pressed. Unfortunetaly, nothing worked for me. Is there a easy way to do this? I just need something like




     variableNumber = 1;



Then I want to check some variables, so I tried to use the console from the debug layer:



The console still tells me only that the Babylon.js engine launched.

Any way to feed the console?


Thanks for help! :)

Link to comment
Share on other sites

Hi, try this:

var keys={letft:0,right:0,forward:0,back:0};window.addEventListener("keydown", handleKeyDown, false);window.addEventListener("keyup", handleKeyUp, false);function handleKeyDown(evt){    if (evt.keyCode==65){//A        keys.left=1;    }    if (evt.keyCode==68){//D        keys.right=1;    }    if (evt.keyCode==87){//W        keys.forward=1;    }    if (evt.keyCode==83){//S        keys.back=1;    }}function handleKeyUp(evt){    if (evt.keyCode==65){        keys.left=0;    }    if (evt.keyCode==68){        keys.right=0;    }    if (evt.keyCode==87){        keys.forward=0;    }    if (evt.keyCode==83){        keys.back=0;    }}and hereengine.runRenderLoop(function () {     if (keys.left==1)    {        //move left    }    if (keys.right==1)    {        //move right    }    if (keys.back==1)    {        //move back    }    if (keys.forward==1)    {        //move forward    }});

Isn't the best, but is a solution. 

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...