• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 45
  • Last Modified:

Is it possible to determine whether the user is holding the <CTRL> key down when he/she clicks a ToolStripButton?

In a Win Forms app written in C# (Visual Studio 2017)...

Is it possible to determine whether the user is holding the <CTRL> key down when he/she clicks a ToolStripButton? Is so, how?

In the button's event handler I would like to perform conditional actions, dependent upon whether the <CTRL> key has been held down or not

Many Thanks
0
Adrian2504
Asked:
Adrian2504
  • 2
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
from:from:
https://stackoverflow.com/questions/14946912/detecting-ctrlleft-mouse-button-in-mousedown-event-handler

    void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control)
        {
            MessageBox.Show("Control key was held down.");
        }
    }

Open in new window


The target shouldn't matter (EG: form versus a control).
1
 
Adrian2504Author Commented:
That work great. Thanks.
1
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Auto close.  User had agreed the solution worked just didn't close the question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now