2013-01-01 7 views
3

Pyglets Window.on_key_press 및 Window.on_key_release는 <a href="http://www.pyglet.org/doc/programming_guide/keyboard_events.html" rel="nofollow">pyglet's documentation</a>에

The Window.on_key_press and Window.on_key_release events are fired when 
any key on the keyboard is pressed or released, respectively. These events 
are not affected by "key repeat" -- once a key is pressed there are no more 
events for that key until it is released. 

유니티의 키보드 설정이라고하지만 "키 입력이 키를 누르고 있으면 반복"고 적혀있다 키가 눌려지면 pyglet (1.2alpha1)은 on_key_press와 on_key_release를 반복합니다.

import pyglet 

window = pyglet.window.Window() 

@window.event 
def on_key_press(symbol, modifiers): 
    print "key press" 

@window.event 
def on_key_release(symbol, modifiers): 
    print "key release" 

pyglet.app.run() 

하나의 윈도우 키 반복을 오버라이드 (override) 할 수있는 방법이 있나요 :

이 의도하지 않은 행동

는 다음 스크립트에 의해 전환 설정을 테스트 할 수 있습니까? 다른 해결 방법도 환영합니다.

이 설정은 기본적으로 켜져 있으며 게임에서 설정을 요청하는 것이 좋지 않습니다.

답변

2

간단한 해결 방법은 될 것 같은 뭔가 :

pressed_keys = [] 

@window.event 
def on_key_press(symbol, modifiers): 
    if symbol in pressed_keys: 
     return 
    # handle pressed key 
    pressed_keys.append(symbol) 

@window.event 
def on_key_release(symbol, modifiers): 
    if symbol in pressed_keys: 
     pressed_keys.remove(symbol)