How can I determine when the control key is held down during button click in a C# Windows program? I want one action to take place for Ctrl/Click and a different one for Click.
Recovery: Most of the time, Ctrl+Alt+Del re-sets key status to normal if this is happening. (Then press Esc to exit system screen.) Another method: You can also press stuck key: so if you clearly see that it is Ctrl which got stuck, press and release both left and right Ctrl.
While holding down the Ctrl key you can left-click to select multiple objects or highlight multiple sections of text. For example, in Microsoft Windows you could hold down the Ctrl key and click to select multiple files at once.
Go to Start / Settings / Control Panel / Accessibility Options /Keyboard Options. b. Turn off CTRL lock if it's on. d.
And a little bit more:
private void button1_Click ( object sender, EventArgs e )
{
if( (ModifierKeys & Keys.Control) == Keys.Control )
{
ControlClickMethod();
}
else
{
ClickMethod();
}
}
private void ControlClickMethod()
{
MessageBox.Show( "Control is pressed" );
}
private void ClickMethod()
{
MessageBox.Show ( "Control is not pressed" );
}
Assuming WinForms, use Control.ModifierKeys, eg:
private void button1_Click(object sender, EventArgs e) {
MessageBox.Show(Control.ModifierKeys.ToString());
}
Assuming WPF, use Keyboard.Modifiers, eg:
private void Button_Click(object sender, RoutedEventArgs e) {
MessageBox.Show(Keyboard.Modifiers.ToString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With