本文整理匯總了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