0

Hi I need help in detecting the space bar when pressed. My program listed below wont detect the space bar. I wont to put the contents of a text file on the screen and then copy that text by typing it - so when I press the corresponding key the program will print to screen that letter from my text. If I press the wrong letter nothing happens. IT WORKS FOR THE FIRST 2 LETTERS BUT THE PROGRAM WONT DETECT THE SPACE IN THE STRING WHEN I PRESS IT, IT JUST STOPS. So I need help so I can copy the whole String out using keyboad.read_key(). I'm writing a typing practice program for my first program. The text is: In the beginning The output is: I N

import keyboard
d = 0
e = 1
f = open("C:/BibNum/Paragraphs/TEST18.txt")
a = f.read().replace("\n","")
   print(a)
   f.close()
   c = a[d:e]
while True:
    c = a[d:e]
if keyboard.read_key()== c:
    print (c)
    d = d + 1
    e = e + 1
            
Chris
  • 1
  • 1

1 Answers1

0
import keyboard
ed = 0
e = 1
f = open("C:/BibNum/Paragraphs/TEST18.txt")
a = f.read().replace("\n"," ")
   print(a)
   f.close()
   c = a[d:e]
while True:
    c = a[d:e]
    if keyboard.read_key()== c:
        print (c)
        d = d + 1
        e = e + 1
            

Try this code

Pavlo
  • 166
  • 1
  • 11
  • I don't understand Pavlo you just copied the code I wrote. By the way I fixed the variable name in line 2 fro ed = 0 to d = 0 – Chris Dec 27 '20 at 11:57