Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key variable is empty #48

Closed
codeanticode opened this issue Aug 26, 2013 · 2 comments
Closed

key variable is empty #48

codeanticode opened this issue Aug 26, 2013 · 2 comments
Assignees
Labels

Comments

@codeanticode
Copy link
Member

It seems that the key variable is not properly set. if I add the following code to my sketch:

var keyPressed = function() {
println("key: |" + key + "| (" + keyCode + ")");
};

then I get this output in the console:

key: || (0)
key: || (101)
key: || (114)
key: || (101)
key: || (52)
key: || (53)
key: || (53)

Also, the keyCode doesn't appear to be consistent, as it changes when pressing the same key at different times. I'm running Chrome 29.0.1547.57 on OSX 1.6.8.

@ghost ghost assigned lmccart Aug 27, 2013
@brightredchilli
Copy link
Contributor

Hm, looks like some discussion needed here.

The keyPressed function is currently bound to the onkeydown event.

document.body.onkeydown=function(e){
      pKeyPressed = true;
      if (typeof keyPressed === 'function')
        keyPressed(e);
    }    

but we are setting keyCode only on the keypress event.

 document.body.onkeypress=function(e){                                                                              
      keyCode = e.keyCode;
      if (typeof keyTyped === 'function')
        keyTyped(e);
    }    

The bigger issue here is that keyCode only has the correct ASCII representation in onkeypress(Chrome 29.0.1547.57, Firefox 23.0.1). For now, this brightredchilli/processing-js@5fc0667 has a temporary fix, just setting the keyCode in two places. This will at least give some default values to work with.

@lmccart
Copy link
Member

lmccart commented Aug 29, 2013

closing for now. also removing the keycode and key set in onkeypress, this relates to a different code than the keyup and down events which refer to the physical key.

we can look at this when we implement with cross browser support later:
http://unixpapa.com/js/key.html

@lmccart lmccart closed this as completed Aug 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants