Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpad key codes in C#

Tags:

c#

winforms

I use these following codes to work with numpad keys.

if (e.KeyCode == Keys.NumPad0 || e.KeyCode == Keys.D0)
{
   MessageBox.Show("You have pressed numpad0");
}
if (e.KeyCode == Keys.NumPad1 || e.KeyCode == Keys.D1)
{
   MessageBox.Show("You have pressed numpad1");
}

And also for the other numpad keys. But I want to know how I can to this for "+" , "*" , "/" , " -" , " . " which located next to the numpad keys.

Thanks in advance

like image 521
Ali Vojdanian Avatar asked May 16 '12 20:05

Ali Vojdanian


People also ask

How do I type the numpad symbol?

To type these characters you merely have to hold down an ALT key, type the numeric value of the character, then release the ALT key.

What key is numpad on keyboard?

A numeric keypad, number pad, numpad, or ten key, is the palm-sized, usually-17-key section of a standard computer keyboard, usually on the far right.


2 Answers

Check out the entire Keys enum . You have Keys.Mutiply, Keys.Add, and so forth.

Note that Keys.D0 is not the numpad 0, it's the non-numpad 0.

like image 132
zmbq Avatar answered Nov 15 '22 06:11

zmbq


For "+" , "*" , "/" , we can use KeyDown event and for "-" , "." we can use KeyPress event.

Here are the codes :

private void button1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Add)
        {
            MessageBox.Show("You have Pressed '+'");
        }
        else if (e.KeyCode == Keys.Divide)
        {
            MessageBox.Show("You have Pressed '/'");
        }
        else if (e.KeyCode == Keys.Multiply)
        {
            MessageBox.Show("You have Pressed '*'");
        }
    }
private void button1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == '.')
        {
            MessageBox.Show("You have pressed '.'");
        }
        else if (e.KeyChar == '-')
        {
            MessageBox.Show("You have pressed '-'");
        }
    }
like image 32
Ali Vojdanian Avatar answered Nov 15 '22 06:11

Ali Vojdanian