0

I have just been trying to use the keyboard module to sense key presses but I get an error everytime I run the program can someone please help? Here is my code :

import pygame
import keyboard
from sys import exit


pygame.init()
Screen = pygame.display.set_mode((800, 400))
pygame.display.set_caption("Game Test")
clock = pygame.time.Clock()
TheImM = pygame.image.load("images/fireball(1-2).png")
TheImM = pygame.transform.scale(TheImM,(100, 70))
num1 = 0

while True :
  for event in pygame.event.get() :
    if event.type == pygame.QUIT :
      pygame.quit()
      exit()    
  if keyboard.read_key() == "w" :
    for x in range(1,65) :
      Screen.fill((0,0,0))
      Screen.blit(TheImM,(num1,130))
      num1 = num1 + 10
      pygame.display.update()
      clock.tick(30) 
  num1 = 0
  Screen.blit(TheImM,(num1,130))

I have an image(fireball) going across the screen but im trying to get it to go across the screen when I press "w" but I get the error

https://i.stack.imgur.com/PBETp.png

I have tried searching up the error but nothing is working, I use a site called replit and I am on a chromebook, can someone please help? thanks!

  • Please don't post images of error messages, post the error message instead. That being said: What's unclear about the error? – Sören Sep 30 '22 at 16:26
  • I dont know how to fix the error –  Sep 30 '22 at 16:30
  • If you don't post it as part of your question (not a screenshot or a link!), neither do we. (We're not obligated or expected to follow links to answer a question; see [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/a/285557/14122) for backdrop on why: we want to be sure questions remain valid if links break; we want content essential to their validity to be searchable, copy/pasteable, readable for people who use screenreaders / high-vis fonts / etc, etc). – Charles Duffy Sep 30 '22 at 16:38
  • ...that said, have you thought about using a _different_ keyboard library, one that doesn't have that constraint? `pygame` itself has its own keyboard input mechanisms; if you use them instead of this "keyboard" library you won't have this problem. – Charles Duffy Sep 30 '22 at 16:39
  • What is the name of the pygame keyboard library? –  Sep 30 '22 at 16:48

0 Answers0