1

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. My Key_Down method:

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?

Dejan
  • 113
  • 1
  • 9
  • Possible duplicate of [disable beep of enter and escape key c sharp](https://stackoverflow.com/questions/13952932/disable-beep-of-enter-and-escape-key-c-sharp) –  Feb 28 '18 at 12:57
  • Set the event as handled? – Neijwiert Feb 28 '18 at 12:58
  • I set it as handled but it still makes the sound – Dejan Feb 28 '18 at 13:11
  • The linked code also uses `e.SuppressKeyPress = true`. You should try that. – Jimi Feb 28 '18 at 13:21
  • Documentation for SupressKeyPress: 'You can assign true to this property in an event handler such as KeyDown in order to prevent user input. ' But i want user input... – Dejan Feb 28 '18 at 13:25
  • 1
    You'll have to make up your mind. You can use wasd to move a game object *or* you can use it for text input. Not both. – Hans Passant Feb 28 '18 at 13:30

1 Answers1

1

If your are using .NET framework then add this line of code just after your handling:

        e.SuppressKeyPress = true;