Google Closure: An Enter Key Press

How to set up an event handler for when the enter key is pressed withing the Google Closure system.

Real quick thing which was getting the enter key to be handled on press in an input/textbox… though probably other things.

goog.events.listen(element, goog.events.EventType.KEYPRESS, function(a) {
  if(a.keycode === 13) {
    doSomething();
  }
});

This assumes that 13 is the universal id for the enter key. Not sure if there is a case of browser dependent key codes.

2 thoughts on “Google Closure: An Enter Key Press”

Comments are closed.