private void txb_keydown(object sender, KeyEventArgs e)
{
    //check if A key was pressed
    if (e.KeyCode == Keys.A
    {
     //OK
     }
}

The above code works fine, but how can I do this for the % key?
Looked everywhere, I can check for the tilde key etc. but I can't seem to find the Keys enumeration code for the % key.
Any help will be much appreciated.

There is no % key, so it would be hard to find it. but what there is, would be a shift modified D5 key. So you look for a combination of those keys.

add this to your keydown event:

if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.D5)
            {
                MessageBox.Show("% Key Pressed");
            }

NOTE:
for the alt or ctrl key, its not necessary to check the e.modifiers flag, but when using the shift key it is. I don't know why. I have just tried with it for a while and I ended up with this combination of event data to be the only one that worked.

But there you go, Hope this solves your problem.

You gave me insights! Thank you.
My keyboard on my Mac with VISTA is AZERTY, yours is probably QUERTY. (This Mac was practically a free gift from my boss so I could not refuse) I never found a way to type a ] character on it other than by copy and paste or CharMap, and to type {} I have to do weird things, but I can live with it. I seem to remember that on some QUERTY keyboards, the %key was indeed the shift D5 key. On my keyboard the %key is near the RETURN key! So your code snippet works if I press my D5key, but not if I press my %key.
Meanwhile I found out that if use the KeyPress event like this :

private void txtb_keypress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == '%')
    {
        MessageBox.Show("%key");
    }
}

I get the functionality I want so I think I'm gonna stick to that.
Thanks again for your effort, I will mark this as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.