0

Enter characters without enter!

i have been trying to make a program using msvcrt and getch, but i failed! i showed it to my proff, and he said im not using the correct command! so if anyone has any idea please help the program is: import msvcrt from msvcrt import getch def distance(times): x=0 y=0 for n in range (0,times): print('etc etc:') in_ch = getch() if with conditions etc etc and the problem is that it just prints times(the variable) times etc etc

7th Dec 2016, 12:20 PM
George Grigi
George Grigi - avatar
7 Respostas
+ 2
First off, get rid of the first import statement, it is redundant. Is there supposed to be more to this? From what I see all this will do is print 'etc etc:' n times (your times var). What is your end goal, or what are you trying to make your program do?
12th Dec 2016, 7:32 AM
Nick Bowling
Nick Bowling - avatar
+ 1
Maybe try to put another conditional for in_ch in the loop. I don't know. I'd play around with this but I don's use a MS OS. I just use Linux so I can't use msvcrt. Good luck, sorry I couldn't be more helpful, I'm just beginning myself.
13th Dec 2016, 6:44 PM
Nick Bowling
Nick Bowling - avatar
0
i want the program to print 'etc etc:', then allow the user to enter a character, and without pressing 'enter', i want the program to be able to make that character(string) equal to a variable (in_ch)! i thought that with getch this would happen!
13th Dec 2016, 7:58 AM
George Grigi
George Grigi - avatar
0
I'm still confused. So you want the value of getch() to be assigned to in_ch? Is getch() working, as in is it allowing you to input a char, and the the problem you are having is getting it assigned to in_ch, or is getch() not working at all? Try using getche() while debugging, it echoes your input char. Sorry, I've never used msvcrt and am not at a box to play around.
13th Dec 2016, 3:29 PM
Nick Bowling
Nick Bowling - avatar
0
let me say in a different way i want the program to work like,a similar program in a game for example when i tyle 'w' without pressing the the button enter, the program takes the character that i wanted it and etc etc_! i dont know if you understood this way :p but i will try the getche() and see id something happens
13th Dec 2016, 3:42 PM
George Grigi
George Grigi - avatar
0
What does this snip do if you run it? from msvcrt import getch while True: in_ch = getch() print(in_ch)
13th Dec 2016, 3:54 PM
Nick Bowling
Nick Bowling - avatar
0
I will try it when i arrive at home! The main problem is that the way my program was, it just skips the getch() and printed n times the text within the print! I wanted my program, everytime it prints the text, to stop wait for the user to input a character(to be specific: h or f or g or q) and the moment it assigns the character without pressing enter, then passes through the various if(s), and then repeat n-1 times!
13th Dec 2016, 6:18 PM
George Grigi
George Grigi - avatar