0

I want to make a program in python (windows computer) that can transmit Morse code. If i press 'b' in python shell i want a the computer to respond directly with a long beep. The same when i press 'n', then the program should give a short beep. I can do this with raw_input but then i have to press enter each time i press 'b' or 'n'. How can i do this without having to press enter each time and just get a instant respond with a beep?

I have already tried this:

def Transmit():

    c = 1
    while c == 1:
        a = raw_input("Press key: ")
        if a == "b":
            winsound.Beep(1000, int(1000*x))
        if a == "n":
            winsound.Beep(1000, int(3000*x))

And the function msvcrt.getch doesn't seem to be wroking in my python shell..

1 Answers1

0

Use msvcrt.getch*:

import winsound
import msvcrt

x = 0.1
while 1:
    a = msvcrt.getch()
    if a == "b":
        winsound.Beep(1000, int(1000*x))
    if a == "n":
        winsound.Beep(1000, int(3000*x))
falsetru
  • 357,413
  • 63
  • 732
  • 636