Is there a way to program a function that takes user input without requesting it? For example, during a game of tic-tac-toe, the user could press “Q” at any time and the program would close?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a few ways to do this, and they are all different.
If your game is a terminal application using
curses, you would catch theqwhen you callgetch(), and then raiseSystemExitor simply break out of yourwhileloop that manycursesapplications use.Using
tkinteror another GUI library, you would bind a key press event to yourFramewidget that holds the tic-tac-toe board.