本文整理匯總了Python中pyglet.window.key.DOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python key.DOWN屬性的具體用法?Python key.DOWN怎麽用?Python key.DOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pyglet.window.key
的用法示例。
在下文中一共展示了key.DOWN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: pyglet_key_down
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def pyglet_key_down(self, symbol, modifier, repeat_in=0.3):
from pyglet.window import key
self.last_key_down = symbol
self.last_key_modifier = modifier
self.next_key_repeat = time.time() + repeat_in
is_ascii = 27 <= symbol < 255
char = {
key.LEFT: KEYS.LEFT_ARROW,
key.RIGHT: KEYS.RIGHT_ARROW,
key.UP: KEYS.UP_ARROW,
key.DOWN: KEYS.DOWN_ARROW,
key.ENTER: '\r',
key.RETURN: '\r',
key.BACKSPACE: chr(127),
}.get(symbol, chr(symbol) if is_ascii else None)
if not char:
# All other characters don't count as a key press
# (e.g., function keys, modifier keys, etc.)
return
if modifier & key.MOD_SHIFT:
char = char.upper()
self.set_needs_display()
self.handle_input(char)
示例2: update
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def update(dt):
if keys[key.UP]:
monkey.position.z -= .01
elif keys[key.DOWN]:
monkey.position.z += .01
global t
t += .5
monkey.rotation.y = t
for cam in camera.cameras:
cam.uniforms['projection_matrix'] = cam.projection_matrix
示例3: key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_press(k, mod):
global restart
if k==0xff0d: restart = True
if k==key.LEFT: a[0] = -1.0
if k==key.RIGHT: a[0] = +1.0
if k==key.UP: a[1] = +1.0
if k==key.DOWN: a[2] = +0.8 # set 1.0 for wheels to block to zero rotation
示例4: key_release
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_release(k, mod):
if k==key.LEFT and a[0]==-1.0: a[0] = 0
if k==key.RIGHT and a[0]==+1.0: a[0] = 0
if k==key.UP: a[1] = 0
if k==key.DOWN: a[2] = 0
示例5: on_text_motion
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_text_motion(self, motion):
if motion == key.UP:
self.xRotation -= INCREMENT
elif motion == key.DOWN:
self.xRotation += INCREMENT
elif motion == key.LEFT:
self.yRotation -= INCREMENT
elif motion == key.RIGHT:
self.yRotation += INCREMENT
開發者ID:PacktPublishing,項目名稱:Python-GUI-Programming-Cookbook-Second-Edition,代碼行數:11,代碼來源:pyglet_GUI.py
示例6: key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_press(self, k, mod):
if k==key.LEFT: self.move[0] = True
if k==key.RIGHT: self.move[1] = True
if k==key.UP: self.move[2] = True
if k==key.DOWN: self.move[3] = True
示例7: key_release
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_release(self, k, mod):
if k==key.LEFT: self.move[0] = False
if k==key.RIGHT: self.move[1] = False
if k==key.UP: self.move[2] = False
if k==key.DOWN: self.move[3] = False
示例8: on_key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_key_press(symbol, modifiers):
"""
This handler processes keyboard commands that
control the simulation
"""
if symbol == key.BACKSPACE or symbol == key.SLASH:
print('RESET')
env.reset()
env.render('pyglet', view=view_mode)
return
if symbol == key.ESCAPE:
env.close()
sys.exit(0)
if symbol == key.UP:
step(env.actions.move_forward)
elif symbol == key.DOWN:
step(env.actions.move_back)
elif symbol == key.LEFT:
step(env.actions.turn_left)
elif symbol == key.RIGHT:
step(env.actions.turn_right)
elif symbol == key.PAGEUP or symbol == key.P:
step(env.actions.pickup)
elif symbol == key.PAGEDOWN or symbol == key.D:
step(env.actions.drop)
elif symbol == key.ENTER:
step(env.actions.done)
示例9: on_key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_key_press(self, symbol, modifiers):
if symbol == key.DOWN:
self.selected_index += 1
elif symbol == key.UP:
self.selected_index -= 1
else:
self.items[self.selected_index].on_key_press(symbol, modifiers)
self.selected_index = min(max(self.selected_index, 0),
len(self.items) - 1)
if symbol in (key.DOWN, key.UP) and enable_sound:
bullet_sound.play()
示例10: on_key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_key_press(self, symbol, modifiers):
x, y = self.w.get_location()
if symbol == key.LEFT:
x -= 10
if symbol == key.RIGHT:
x += 10
if symbol == key.UP:
y -= 10
if symbol == key.DOWN:
y += 10
self.w.set_location(x, y)
print 'Window location set to %dx%d.' % (x, y)
示例11: on_key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_key_press(self, symbol, modifiers):
if symbol == key.DOWN:
self.selected_index += 1
elif symbol == key.UP:
self.selected_index -= 1
self.selected_index = min(max(self.selected_index, 0),
len(self.items) - 1)
if symbol in (key.DOWN, key.UP) and enable_sound:
bullet_sound.play()
示例12: on_key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def on_key_press(self, symbol, modifiers):
x, y = self.w.get_location()
if symbol == key.LEFT:
x -= 10
if symbol == key.RIGHT:
x += 10
if symbol == key.UP:
y -= 10
if symbol == key.DOWN:
y += 10
self.w.set_location(x, y)
print('Window location set to %dx%d.' % (x, y))
print('Window location now: %dx%d.' % self.w.get_location())
self.assertSequenceEqual((x, y), self.w.get_location())
示例13: key_press
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_press(self, k, mod):
if k == key.LEFT:
self.move[0] = True
if k == key.RIGHT:
self.move[1] = True
if k == key.UP:
self.move[2] = True
if k == key.DOWN:
self.move[3] = True
示例14: key_release
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def key_release(self, k, mod):
if k == key.LEFT:
self.move[0] = False
if k == key.RIGHT:
self.move[1] = False
if k == key.UP:
self.move[2] = False
if k == key.DOWN:
self.move[3] = False
示例15: __init__
# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import DOWN [as 別名]
def __init__(self, character=characters.Bomber, agent_control='arrows'):
super(PlayerAgent, self).__init__(character)
##
# @NOTE: DO NOT move this import outside the constructor. It will
# not work in headless environments like a Docker container
# and prevents Pommerman from running.
#
from pyglet.window import key
controls = {
'arrows': {
key.UP: 1,
key.DOWN: 2,
key.LEFT: 3,
key.RIGHT: 4,
key.SPACE: 5,
key.M: 6 # In Pommerman, this will freeze the game.
},
'wasd': {
key.W: 1,
key.S: 2,
key.A: 3,
key.D: 4,
key.E: 5,
key.Q: 6 # In Pommerman, this will freeze the game.
}
}
assert agent_control in controls, "Unknown control: {}".format(
agent_control)
self._key2act = controls[agent_control]
self._action_q = []
self._keystate = {}