Я пытаюсь сделать поле ввода.Таким образом, мы можем что-то напечатать в нем.
Первая проблема, с которой я столкнулся, заключалась в том, что, когда мы пытаемся удерживать клавишу в течение некоторого времени, она повторяется только один раз.Теперь это было решено с помощью ответов, сделанных по этой ссылке: Удержание клавиши Pygame?
Однако проблема, с которой сейчас сталкиваются, заключается в том, что когда мы пытаемся нажать клавишу только один разиногда это повторяется более одного раза (дважды или чаще).
Псевдокод выглядит так:
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
self.quit_screen = True
# events related to the input box
if event.type == pygame.MOUSEBUTTONDOWN:
#Things related to it
#Disactivate the typing on the input box if KEYUP activated
if event.type == pygame.KEYUP:
self.typing = False
self.backspace_pressed = False
if event.type == pygame.KEYDOWN:
print("KEYDOWN\n")
if self.user_input_box.input_box_active:
# If we press 'enter', we save
if event.key == pygame.K_RETURN:
#save the text in some variables
# If we press the key '\b' (backspace), we delete a caracter
elif event.key == pygame.K_BACKSPACE:
self.backspace_pressed = True
else: #Get the current letter
self.typing = True
self.cur_letter = event.unicode
if self.typing: #Adding the letter saved in cur_letter to the current text(user_entry)
self.user_input.user_entry += self.cur_letter
if self.backspace_pressed:
self.user_input.user_entry = self.user_input.user_entry[:-1]