Reputation: 17
I am making a chat app in Replit through Python. I have a while true loop that checks if a message has been posted and will check if you pressed the T key, and if so, pauses the loop to let you type and send your message. Because it is on replit, I cannot give root access.
I have tried using the keyboards module functions, like keyboard.is_pressed('t')
, but that requires root access. I have looked through the docs there and have not found anything. I have also tried using the solutions in How to detect key presses?.
Upvotes: 0
Views: 653
Reputation: 17
I used the getKey
Module for it:
from getkey import getkey
key = getkey()
if key == 't':
Upvotes: 0
Reputation: 945
I am not familiar with Replit, but, if you're on a Windows machine, you might solve it with :
import msvcrt
while True:
# Check if a message has been posted
# ...
# Check if the 't' key has been pressed
if msvcrt.kbhit():
# Read the character from the keyboard
ch = msvcrt.getch()
if ch == b't':
# Pause the loop and let the user type and send a message
# ...
Not sure if it helps for your usecase, maybe for others. cheers.
Upvotes: 0