xyz
xyz

Reputation: 27837

Windows - Can console output inadvertently cause a system beep?

I have a C# console application that logs a lot to the console (using Trace). Some of the stuff it logs is the compressed representation of a network message (so a lot of that is rendered as funky non-alphabetic characters).

I'm getting system beeps every so often while the application is running. Is it possible that some "text" I am writing to the console is causing them?

(By system beep, I mean from the low-tech speaker inside the PC case, not any kind of Windows sound scheme WAV)


If so, is there any way to disable it for my application? I want to be able to output any possible text without the it being interpreted as a sound request.

Upvotes: 4

Views: 2646

Answers (6)

mafu
mafu

Reputation: 32650

Even if you check the input for BELL characters, it may still beep. This is due to font settings and unicode conversion. The character in question is U+2022, Bullet.

Raymond Chen explains:

In the OEM code page, the bullet character is being converted to a beep. But why is that?

What you're seeing is MB_USEGLYPHCHARS in reverse. Michael Kaplan discussed MB_USEGLYPHCHARS a while ago. It determines whether certain characters should be treated as control characters or as printable characters when converting to Unicode. For example, it controls whether the ASCII bell character 0x07 should be converted to the Unicode bell character U+0007 or to the Unicode bullet U+2022. You need the MB_USEGLYPHCHARS flag to decide which way to go when converting to Unicode, but there is no corresponding ambiguity when converting from Unicode. When converting from Unicode, both U+0007 and U+2022 map to the ASCII bell character.

Upvotes: 3

paxdiablo
paxdiablo

Reputation: 881403

That's usually caused by outputting character code 7, CTRL-G, which is the BEL (bell) character.

The first thing I normally do when buying a new computer or motherboard is to ensure the wire from the motherboard to the speaker is not connected. I haven't used the speaker since the days of Commander Keen (and removing that wire is the best OS-agnostic way of stopping the sound :-).

Upvotes: 19

Jorge Zuanon
Jorge Zuanon

Reputation: 1354

HKEY_CURRENT_USER\Control Panel\Sound

set the "Beep" key to "no".

Upvotes: 5

SqlACID
SqlACID

Reputation: 4014

If you don't want if to beep, you'll either have to replace the 0x7 character before outputting it, or disable the "Beep" device driver, which you'll find in the Non-Plug and Play Drivers section, visible if you turn on the Show Hidden Devices option. Or take the speaker out.

Upvotes: 3

Marko
Marko

Reputation: 31385

\b in output string will cause beep, if not disabled on the OS level.

Upvotes: 1

Ben Schwehn
Ben Schwehn

Reputation: 4565

absolutely, if you output ASCII control code "Bell" (0x7) to a console, it beeps.

Upvotes: 4

Related Questions