0
#include<stdio.h>
#include<Windows.h>

int main()
{
    printf("if you want to stop using morse code, press n\n");
    int input;
    int dot, dash;

    dot = '.', dash = '-';

    while (1) {
        if (kbhit()) {
            input = _getch();
            switch (input) {
            case 115: Beep(260, 200); printf("%c", dot); break;

            case 108: Beep(260, 500); printf("%c", dash); break;
            }

            if (input == 110) {
                break;
            }
        }

    }
    return 0;
}

If I type s and n keys sequentially quickly, the sound will delay for 0.1 seconds. How can I make a sound without delay every time I press it?

wohlstad
  • 12,661
  • 10
  • 26
  • 39
const
  • 1
  • What exactly is the problem? Is it that if if you press a new button while the sound for the previously pressed button is still playing, the previous sound will first finish playing before the new sound starts playing? Is the problem that you want the previously playing sound to abort immediately, so that the new sound starts playing immediately after the keypress? Or is the problem that there is a short moment of silence after the previous sound finishes, before the new sound starts playing? – Andreas Wenzel Mar 17 '22 at 16:03
  • If the problem is the former, then the following link may be helpful: [How would I include a beep sound without causing a delay in C++?](https://stackoverflow.com/q/71254818/12149471) – Andreas Wenzel Mar 17 '22 at 16:07
  • 1
    Side note: Your code would be easier to read if you wrote `'s'` instead of `115`. – Andreas Wenzel Mar 17 '22 at 16:18

0 Answers0