本文整理汇总了Python中keyboard.Keyboard.set_key_down方法的典型用法代码示例。如果您正苦于以下问题:Python Keyboard.set_key_down方法的具体用法?Python Keyboard.set_key_down怎么用?Python Keyboard.set_key_down使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyboard.Keyboard
的用法示例。
在下文中一共展示了Keyboard.set_key_down方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Screen
# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import set_key_down [as 别名]
size = width, height = 64*scale_factor, 32*scale_factor
pygame.init()
pygame.mixer.init()
app_screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)
pygame.display.set_caption('Chip8 Emulator')
sound = pygame.mixer.Sound("Buzzer_short.ogg")
screen = Screen(width, height, scale_factor)
keyboard = Keyboard()
cpu = CPU(config, screen, keyboard, sound)
cpu.load_rom_into_memory(config.get('ROM', 'path'))
run_loop = True
while run_loop:
pygame.time.wait(cpu.clock_freq)
cpu.execute_instruction()
cpu.screen.redraw(app_screen)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run_loop = False
sys.exit()
if event.type == pygame.KEYDOWN:
if pygame.key.name(event.key) in keyboard.keymap.keys():
keyboard.set_key_down(pygame.key.name(event.key))
if event.type == pygame.KEYUP:
if pygame.key.name(event.key) in keyboard.keymap.keys():
keyboard.reset_key_state()