Click here to Skip to main content
15,310,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys, i want to know i know how to perform click on key down event but i dont know how to use double short keys for this i mean to say when i am pressing c so button 15 perform click but i want to do this with shift + c

Thanks

What I have tried:

C#
private void Main_Form_KeyDown(object sender, KeyEventArgs e)
      {
          if (e.KeyCode == Keys.C)
          {
              MessageBox.Show("Enter Key Pressed ");
              button15.PerformClick();
          }
          else if (e.KeyCode == Keys.K)
          {
              MessageBox.Show("Enter Key Pressed ");
              button16.PerformClick();
          }
      }
Posted
Updated 12-Dec-16 6:08am
Comments
[no name] 8-Dec-16 15:43pm
   
You have to check the KeyEvetnArgs modifier property.
Mehedi Shams 8-Dec-16 20:23pm
   
Hi Member 9983063, can you please elaborate the problem a little bit more? Did you mean you want to perform the action using Shift+C (instead of 'C' or 'c')?
Philippe Mori 12-Dec-16 16:33pm
   
What is the relation between Shift + C and your code?

1 solution

This seems related: Double Key Code.

If what you are trying to achieve is using the Shift Key and the C key to do the button15.PerformClick() then you have to check the Modifiers in the KeyEventArgs instance.

Try this:
C#
private void Main_Form_KeyDown(object sender, KeyEventArgs e)
      {
          // Alternatively you can just check e.Shift
          // if (e.KeyCode == Keys.C && e.Shift) 
          if (e.KeyCode == Keys.C && e.Modifiers == Keys.Shift)
          {
              MessageBox.Show("Enter Key Pressed ");
              button15.PerformClick();
          }
          else if (e.KeyCode == Keys.K)
          {
              MessageBox.Show("Enter Key Pressed ");
              button16.PerformClick();
          }
      }
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900