You want `CodeMirror.on(cm.getWrapperElement(), "keydown", function(e) {...})` -- i.e. the static function on the `CodeMirror` object takes three arguments, with the first being the object to listen on. `cm.on` is a shorthand for this that has `cm` bound as the first argument.