+ 8
How to get only a single character as input without pressing enter ?
i am planning to get the inputs as a single character as it is being typed. I want to receive it without pressing enter . Any help available? Thanks in advance 😊
8 odpowiedzi
+ 17
Unfortunately, module curses is not available in Sololearn. They really need to fix the Code Playground, starting with the input system.
+ 8
Something like this:
I haven't ever really used this before so I found this question interesting and looked it up in the python docs. Note this is for python 3.5, but I didn't see much difference for other versions.
https://docs.python.org/3.5/library/curses.html
https://docs.python.org/3.5/library/curses.html#window-objects
import curses
screen = curses.initscr()
curses.cbreak()
screen.keypad(1)
screen.addstr("Enter q to quit ")
screen.refresh()
key = ''
while key != ord('q'):
key = screen.getch()
screen.addch(key)
screen.refresh()
curses.endwin()
+ 2
I love that's app
Thanks u very match
+ 1
if you are using c language or c++
you can use a loop and condition along with the _kbhit () and _getch () functions.
while (_khbit)
{
_getch();
}
but this code is useless.
you need to implement an idea.
The kbhit is to tell the computer a key has been hit.
the getch gets the key that was hit without prompt.
0
Thanks...
I'll try this code and ping you if any queries arises
0
;)
0
I love that's app
Thanks u very match
- 1
i love this app