Skip to content
← Back to Community
Help using getch
Profile icon
Trex10

Hello,
In this program I'm trying to make a letter run around the screen using WASD, is there any built in getch(or python/any other module) function that can help me with this? If not, can you show me how to do this since I'm having some difficulties with the letter jumping two spaces and only backing up once.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
Trex10
Comments
hotnewtop
Profile icon
Coder100

I would recommend using curses for this. Not only does it have getch 'built-in' (getch was actually inspired curses), you can set it on the y and x
https://docs.python.org/3/library/curses.html

Profile icon
Trex10

@Coder100
hmmmm, I'm confused, which thing would let me move the letter easier?

Profile icon
Coder100
Profile icon
plscodeinjava

ur a noob

Profile icon
Coder100

can ya first make the variables slightly sane

Profile icon
Trex10

@Coder100
nah I don't need to

Profile icon
Coder100

anyways read my other comment @Trex10

Profile icon
RYANTADIPARTHI

Solution

yes, getch works for WSAD. Try this code for it.

import getch ques = getch.getch() print('WSAD?') if ques == 'W': # something elif ques == 'S': # something elif ques == 'A': # something else: # something

like that.
That should work

Profile icon
Trex10

@RYANTADIPARTHI
yes, I have my code like that,but is there any way I can do something like getch.pythonpoggers.movethingy to move the letter?

Profile icon
RYANTADIPARTHI

@Trex10 no, i don't think you can do it like that.

Profile icon
SixBeeps

From what I've seen, the getch package (which you're using now) is pretty much your only option. Can't tell you why you're getting double triggers especially since you're flushing the buffer already, but I can confirm there is no built-in getch.

Profile icon
Trex10

@SixBeeps
I really don't know what the flush thing or almost everything else in that line does. I just found it on StackOverflow and put it in here

Profile icon
Trex10

@SixBeeps
Also, I meant to ask is there something built into getch that allows me to move the letter?

Profile icon
SixBeeps

@Trex10 Nope, there wouldn't be a good enough reason for them to.

Profile icon
Trex10

@SixBeeps
ok, I gtg right now so I guess I'll have to fix the issues later I'll be back tomorrow.