1

This is My Code, I'm a beginner and I've been looking around I've looked at least 5-10 posts about this, they aren't really helping me because I can't understand the code.

In My code im trying a really basic starting screen for a game and what I want to do is how detect E or S being pressed at the time of the start screen,

print (" _____________________________________________ ")
print ("|                                             |")
print ("|                                             |")
print ("|          The Chronicles                    |")
print ("|                Of Game                      |")
print ("|                                             |")
print ("|                                             |")
print ("|                                             |")
print ("|                                             |")
print ("|_____________________________________________|")
print ("|                                             |")
print ("|       START             EXIT                |")
print ("|        (S)               (E)                |")
print (" \___________________________________________/ ")
1
  • 1
    This is OS dependent, so say which OS you are using. Commented Oct 3, 2015 at 1:40

1 Answer 1

1

I use getch, if you want to use, download py-getch:

https://github.com/joeyespo/py-getch

the command to install: python setup.py install

Example code:

from getch import getch, pause

# game loop
while(True):
    key = getch()
    if(key == 'S'):
        print('key S pressed...')
    elif(key == 'E'):
        print('key E pressed...')

key pressed

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks im going to try this one out
I tried this, and it works. However, it breaks the terminal. So I have to do a reset to get everything back. Moreover, when using try it does not catch except KeyboardInterrupt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.