本文整理汇总了Python中pybullet.getKeyboardEvents方法的典型用法代码示例。如果您正苦于以下问题:Python pybullet.getKeyboardEvents方法的具体用法?Python pybullet.getKeyboardEvents怎么用?Python pybullet.getKeyboardEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybullet
的用法示例。
在下文中一共展示了pybullet.getKeyboardEvents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_key_pressed
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getKeyboardEvents [as 别名]
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
示例2: _key_events_fetcher
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getKeyboardEvents [as 别名]
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