code: def mode_key_down(self, viewer, keyname):
          if keyname not in self.mode_map:
              if (keyname not in self.mode_tbl) or (self._kbdmode != 'meta'):
                  return False
              bnch = self.mode_tbl[keyname]
          else:
              bnch = self.mode_map[keyname]
          mode_name = bnch.name
          self.logger.debug("cur mode='%s' mode pressed='%s'" % (
              self._kbdmode, mode_name))
          if mode_name == self._kbdmode:
              self.reset_mode(viewer)
              return True
          if self._delayed_reset:
              self._delayed_reset = False
              return True
          if ((self._kbdmode in (None, 'meta')) or
              (self._kbdmode_type != 'locked') or (mode_name == 'meta')):
              if self._kbdmode is not None:
                  self.reset_mode(viewer)
              if self._kbdmode in (None, 'meta'):
                  mode_type = bnch.type
                  if mode_type is None:
                      mode_type = self._kbdmode_type_default
                  self.set_mode(mode_name, mode_type)
                  if bnch.msg is not None:
                      viewer.onscreen_message(bnch.msg)
                  return True
          return False