title: Pygame: How to catch user input after they press the ENTER key
body: <p>I am making a text based RPG as my first python/pygame project. In my game I would like to present the player with choices then ask them to type it in. I was able to download and import a module which accepts user input and displays it on the screen. However, before using it for anything like..lets say, if the user input is 'yes', then they go to a new area, I'd like the program to only accept the user input once they hit the enter key. I believe the tutorial for the textinput module I downloaded has directions to do this, but to be honest I just don't understand what it's saying. I've tried multiple types of loops but nothing is happening. Any help will be appreciated. Here is my main game code:</p>
  <pre><code>import pygame_textinput
  import pygame
  pygame.init()
  #fps
  clock=pygame.time.Clock()
  # create font here
  font_name = pygame.font.get_default_font()
  WHITE_TEXT_COLOR = (255, 255, 255)
  # create screen and window and display and font here
  screen_width, screen_height = 800, 700
  background_color_black = (0, 0, 0)
  screen = pygame.display.set_mode((screen_width, screen_height))
  our_game_display = pygame.Surface((screen_width, screen_height))
  pygame.display.set_caption('MyRPGGame')
  #create text input object
  textinput = pygame_textinput.TextInput()
  
  
  
  
  
  
  
  def draw_text(text, size, x, y):
          pygame.font.init()
          font = pygame.font.Font(font_name, size)
          text_surface = font.render(text, True, WHITE_TEXT_COLOR)
          text_rect = text_surface.get_rect()
          text_rect.center = (x, y)
          our_game_display.blit(text_surface, text_rect)
  
  
  def choose_to_play():
      draw_text(&quot;You've decided to play&quot;,20,screen_width/2,screen_height/2+50)
  
  def first_area():
          our_game_display.fill(background_color_black)
          draw_text('The story of this game depends on your choices. Do you wish to play?', 20, screen_width / 2,screen_height / 2 - 100)
          draw_text('Type your answer and hit enter.', 20, screen_width / 2,screen_height / 2 - 50)
          draw_text('Yes', 20, screen_width/2,screen_height/2+50)
          draw_text('No', 20, screen_width/2,screen_height/2+100)
  
  
          screen.blit(our_game_display, (0, 0))
          pygame.display.update()
  
  
  while True:
  
      our_game_display.fill((background_color_black))
  
      events = pygame.event.get()
      for event in events:
          if event.type == pygame.QUIT:
              exit()
  
      first_area()
      # Feed it with events every frame
      textinput.update(events)
  
  
  
      # Blit its surface onto the screen
      screen.blit(textinput.get_surface(), (10, 600))
  
      pygame.display.update()
      clock.tick(30)
  </code></pre>
  <p>Now here is the source for the pygame textinput module, figured I would link to the code so this post isn't too crowded:
  <a href="https://github.com/Nearoo/pygame-text-input" rel="nofollow noreferrer">https://github.com/Nearoo/pygame-text-input</a></p>