OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Keypresses not being detected [pygame]

  • Thread starter Thread starter Baldi
  • Start date Start date
B

Baldi

Guest
Code:
import pygame
from pygame.locals import *

class Char(pygame.sprite.Sprite):

    def input(self):
        keys = pygame.key.get_pressed()
        print("input")
        if keys[K_w]:
            self.yv = self.speed
            print("button")
        if keys[K_s]:
            self.yv = -self.speed
            print("button")
        if keys[K_d]:
            self.xv = self.speed
            print("button")
        if keys[K_a]:
            self.xv = -self.speed
            print("button")
    
    def update(self):
        self.input()

player = Char()

while True:
    player.update()
    screen.blit(player.image, round(player.pos))

Keypresses are not being detected in my program. "input" is returned but not "button". I've used code like this in other projects before but for some reason nothing seems to be working here. Any help would be appreicated.
<pre><code>import pygame
from pygame.locals import *

class Char(pygame.sprite.Sprite):

def input(self):
keys = pygame.key.get_pressed()
print("input")
if keys[K_w]:
self.yv = self.speed
print("button")
if keys[K_s]:
self.yv = -self.speed
print("button")
if keys[K_d]:
self.xv = self.speed
print("button")
if keys[K_a]:
self.xv = -self.speed
print("button")

def update(self):
self.input()

player = Char()

while True:
player.update()
screen.blit(player.image, round(player.pos))
</code></pre>
<p>Keypresses are not being detected in my program. "input" is returned but not "button". I've used code like this in other projects before but for some reason nothing seems to be working here. Any help would be appreicated.</p>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
Top