Ask coding questions

← Back to all posts
How would I do something like this with python :
srsly (30)

if keypress = "a"
print("AAAAAA")

Comments
hotnewtop
RYANTADIPARTHI (6006)

Solution

use a module called getch. It detects it. You could also use the usual input. Try these two examples

import getch

key = getch.getch()
if key == "a":
    print("AAAAAA")

or

key = input("type something : ")
if key == "a":
    print("AAAAAA")

like that.
Any of them should work

srsly (30)

@RYANTADIPARTHI oh tysm but I might stick with the keyboard module because it is more original
(also it is literally called keyboard)

srsly (30)

@RYANTADIPARTHI wait the getch and keyboard didnt work can you give an example with getkey?

RYANTADIPARTHI (6006)

@srsly getkey won't work with letters. only up, down, left, right.

srsly (30)

@RYANTADIPARTHI oh can you reccomend another package or give a getkey example because that is fine too.

RYANTADIPARTHI (6006)

@srsly input is the easiest one. It's without packages, and comes built in. You could use getch too. That's it.

srsly (30)

@RYANTADIPARTHI can you give me an example of input?
(sorry im asking to many questions)

RYANTADIPARTHI (6006)

@srsly i did. Check my first comment. and no problem about so many questions

mesquite2234 (278)

Use the getch module

from getch import getch

keypress = getch()
if keypress.lower() == "a":
  print("AAAAAA")