- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在 C# 中使用 PC 扬声器发出哔声。使用以下代码时:
[DllImport("kernel32.dll", EntryPoint = "Beep", SetLastError = true,
ExactSpelling = true)]
public static extern bool Beep(uint frequency, uint duration);
static void Main()
{
while (true)
{
Beep(1000, 500);
Thread.Sleep(2000);
}
}
它不是通过 PC 扬声器发出哔哔声,而是简单地将给定频率和持续时间的声音输出到默认声音设备(例如耳机)。使用 Console.Beep()
时也会发生同样的事情。
为什么?
注意事项:
PC 扬声器已打开。当我启动电脑时,它会发出哔哔声。
操作系统为 Windows 8。
最佳答案
从 Windows 7 开始,您无法再通过内置扬声器轻松发出声音。
For Windows 7, we resolved the issue completely – we moved all the functionality that used to be contained in Beep.Sys into the user mode system sounds agent – now when you call the Beep() API instead of manipulating the 8254 chip the call is re-routed into a user mode agent which actually plays the sounds.
[…]
There were also some unexpected consequences. The biggest was that people started noticing when applications called Beep(). They had placed their PCs far enough away (or there was enough ambient noise) that they had never noticed when their PC was beeping at them until the sounds started coming out their speakers.
详情请看这里
关于c# - 如何使用PC扬声器发出哔哔声?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12794846/
我是一名优秀的程序员,十分优秀!