本文整理汇总了Python中pyglet.window.Window.on_key_press方法的典型用法代码示例。如果您正苦于以下问题:Python Window.on_key_press方法的具体用法?Python Window.on_key_press怎么用?Python Window.on_key_press使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet.window.Window
的用法示例。
在下文中一共展示了Window.on_key_press方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import on_key_press [as 别名]
def main():
win = Window(fullscreen=True, visible=False)
camera = Camera(win.width, win.height, (0, 0), 100)
renderer = Renderer()
maze = Maze()
maze.create(50, 30, 300)
keyboard = Keyboard()
keyboard.key_handlers[key.ESCAPE] = win.close
keyboard.key_handlers.update(camera.key_handlers)
clock.schedule(maze.update)
win.on_draw = lambda: renderer.on_draw(maze, camera, win.width, win.height)
win.on_key_press = keyboard.on_key_press
keyboard.print_handlers()
win.set_visible()
app.run()
示例2: make_army
# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import on_key_press [as 别名]
def make_army(size, menagerie):
army = []
for col in range(size):
for row in range(size):
creature_type = menagerie[randint(0, len(menagerie)-1)]
x = (col+0.5)*16 - size * 8
y = (row+0.5)*16 - size * 8
creature = Creature(creature_type, (x, y))
creature.da = uniform(-0.1, +0.1)
creature.velocity = uniform(0, +0.5)
army.append(creature)
return army
creatures = make_army(12, [blue_ghost, orange_ghost, pacman, pink_ghost, red_ghost])
def update(dt):
for creature in creatures:
creature.update(dt)
clock.schedule(update)
key_handlers[key.ESCAPE] = win.close
win.on_draw = lambda: renderer.on_draw(creatures, camera, win.width, win.height)
win.on_key_press = on_key_press
print "keys to try:", [symbol_string(k) for k in key_handlers.keys()]
stdout.flush()
win.set_visible()
app.run()
示例3: InputManager
# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import on_key_press [as 别名]
print "\tdown is pushed"
if not state:
print "\tdown is released"
# SPACJA
print
state = subject.get_key_state("space");
if state:
print "\tspace is pushed"
if not state:
print "\tspace is released"
# Utworzenie InputManagera i włączenie go do pygleta
manager = InputManager()
window = Window()
window.on_key_press = manager.key_pressed
window.on_key_release = manager.key_released
# Tworzymy 3 obiekty obserwujące
ops1 = ConcreteInputObserver('ops1')
ops2 = ConcreteInputObserver('ops2')
ops3 = ConcreteInputObserver('ops3')
# dodajemy obserwatorów
manager.register_observer(ops1)
manager.register_observer(ops2)
manager.register_observer(ops3)
# usuwamy obserwatorów
manager.unregister_observer(ops1)
manager.unregister_observer(ops2)