简体   繁体   English

C# 如何在按下 w、s、a、d 按钮时删除“叮”系统声音

[英]C# How to remove 'ding' system sound when w,s,a,d buttons are pressed

First of all i can not use首先我不能使用

KeyEventArgs.SuppressKeyPress

Because i am using Key_Down event to listen to input from the user,essentially i am making a Pacman game and when the user presses W or S or A or D there is a 'ding' sound that windows makes.I want to disable it but i do not know how.因为我正在使用 Key_Down 事件来监听用户的输入,本质上我正在制作 Pacman 游戏,当用户按下WSAD 时,Windows 会发出“叮”声。我想禁用它,但是我不知道怎么。 My Key_Down method:我的 Key_Down 方法:

if (e.KeyCode == Keys.A) //A press moves left
        {
            k = 1;
            left = true;
            right = false;
            up = false;
            down = false;
        }
        else if(e.KeyCode == Keys.D) //D press moves right
        {
            k = 3;
            left = false;
            right = true;
            up = false;
            down = false;
        }
        else if(e.KeyCode == Keys.S)
        {
            k = 2;
            left = false;
            right = false;
            up = false;
            down = true;
        }
        else if(e.KeyCode == Keys.W)
        {
            k = 4;
            left = false;
            right = false;
            up = true;
            down = false;
        }

My form uses buttons that i disable when the user presses the 'Start' Button.我的表单使用我在用户按下“开始”按钮时禁用的按钮。 i use:我用:

Button.Disable = true; is it perhaps caused by the buttons still listening for user input or what?可能是由于按钮仍在监听用户输入还是什么引起的? I also have some labels and a Listbox,do i need to disable them too?我还有一些标签和列表框,我是否也需要禁用它们?

如果您使用的是 .NET 框架,那么在您处理之后添加这行代码:

        e.SuppressKeyPress = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM