Python pybullet.getKeyboardEvents() Examples

The following are 3 code examples of pybullet.getKeyboardEvents(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pybullet , or try the search function .
Example #1
Source File: env_modalities.py    From GtS with MIT License 5 votes vote down vote up
def get_key_pressed(self, relevant=None):
        pressed_keys = []
        events = p.getKeyboardEvents()
        key_codes = events.keys()
        for key in key_codes:
            pressed_keys.append(key)
        return pressed_keys 
Example #2
Source File: env_modalities.py    From midlevel-reps with MIT License 5 votes vote down vote up
def get_key_pressed(self, relevant=None):
        pressed_keys = []
        events = p.getKeyboardEvents()
        key_codes = events.keys()
        for key in key_codes:
            pressed_keys.append(key)
        return pressed_keys 
Example #3
Source File: bullet_world.py    From NTP-vat-release with MIT License 4 votes vote down vote up
def _key_events_fetcher(self):
        """Fetch and decode keyboard events in Bullet GUI.

        Returns:
            events: list of (key, key_act, modifiers) tuples.
        """
        # Fetch events
        bullet_events = p.getKeyboardEvents()
        # Map event id to key name
        if self._key_dict is None:
            key_dict = {}
            for i in xrange(128):
                key_dict[i] = str(unichr(i))
            key_dict[65295] = 'LEFT'
            key_dict[65296] = 'RIGHT'
            key_dict[65297] = 'UP'
            key_dict[65298] = 'DOWN'
            key_dict[65309] = 'ENTER'
            self._key_dict = key_dict
        # Map event id to key activity name
        if self._key_act_dict is None:
            key_act_dict = {}
            key_act_dict[1] = 'DOWN'
            key_act_dict[2] = 'TRIGGERED'
            key_act_dict[3] = 'UNKNOWN(3L)'
            key_act_dict[4] = 'RELEASED'
            key_act_dict[5] = 'UNKNOWN(5L)'
            key_act_dict[6] = 'UNKNOWN(6L)'
            self._key_act_dict = key_act_dict
        # Map event id to modifier key names
        if self._modifier_dict is None:
            modifier_dict = {}
            modifier_dict[65306] = 'SHIFT'
            modifier_dict[65307] = 'CTRL'
            modifier_dict[65308] = 'OPTION'
            self._modifier_dict = modifier_dict
        # Decode events
        events = []
        for key, key_act in bullet_events.items():
            if self._key_dict.has_key(key):
                key_name = self._key_dict[key]
            elif self._modifier_dict.has_key(key):
                key_name = self._modifier_dict[key]
            else:
                key_name = None
            key_act_name = self._key_act_dict[key_act]
            events.append((key_name, key_act_name))
        return events