added a bool to disable tick checking if needed
This commit is contained in:
parent
0f69120213
commit
2b2c2d946a
@ -1,5 +1,6 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class InputHandler:
|
||||
"""
|
||||
Class that is implemented into surfaces in order to control the
|
||||
@ -11,15 +12,17 @@ class InputHandler:
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, pygame_clock):
|
||||
def __init__(self, pygame_clock, tick_check=True):
|
||||
"""
|
||||
Create a InputHandler object using a given Pygame clock.
|
||||
|
||||
Args:
|
||||
pygame_clock (pygame.time.Clock): A pygame clock to use as the clock for input time calculations.
|
||||
pygame_clock (:obj:`pygame.time.Clock`): A pygame clock to use as the clock for input time calculations.
|
||||
tick_check (bool, optional): Bool to ignore inputs that happen to quickly after another. Defaults to True.
|
||||
|
||||
"""
|
||||
self.clock = pygame_clock
|
||||
self.tick_check = tick_check
|
||||
self.last_input_tick = 0
|
||||
|
||||
def create_event(self, pressed_button):
|
||||
@ -30,7 +33,11 @@ class InputHandler:
|
||||
|
||||
"""
|
||||
# Register a button click so long as the last button click happened no less than two frames ago
|
||||
if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2 or not gpio_handler.ON_HARDWARE:
|
||||
if self.tick_check:
|
||||
if pygame.time.get_ticks() - self.last_input_tick > self.clock.get_time() * 2:
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
||||
else:
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'key': pressed_button}))
|
||||
pygame.event.post(pygame.event.Event(pygame.KEYUP, {'key': pressed_button}))
|
||||
self.last_input_tick = pygame.time.get_ticks()
|
||||
|
Loading…
Reference in New Issue
Block a user