Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple modifier keys in C#

I am using a keydown event to detect keys pressed and have several key combinations for various operations.

if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control && e.Modifiers == Keys.Shift) {     //Do work } else if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) {     //Paste } 

For some reason the key combination in which I hit Ctrl + Shift + C is not working. I have re ordered them, and placed it at the top thinking it might be interference from the Ctrl + C, and even removed the Ctrl + C to see if it was causing a problem. It still does not work. I know it's probably something very simple, but can't quite grasp what it is. All of my 1 modifier + 1 key combination's work fine, as soon as I add a second modifier is when it no longer works.

like image 368
jsmith Avatar asked Sep 16 '09 19:09

jsmith


People also ask

How many modifier keys are there in keyboard?

Four keys on your keyboard are modifier keys. A modifier key works in combination with other keys to do various interesting and unbelievable things.

Which keys are function modifier keys?

On a Windows keyboard, the modifier keys are Shift, Alt, Control, and the Windows key. On a Mac keyboard, the modifier keys are Shift, Control, Option, and Command (often called the Apple key).


2 Answers

if (e.KeyCode == Keys.C && e.Modifiers == (Keys.Control | Keys.Shift)) {     //Do work } else if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) {     //Paste } 
like image 180
Rom Avatar answered Sep 20 '22 04:09

Rom


Have you tried e.Modifiers == (Keys.Control | Keys.Shift)?

like image 20
Chris J Avatar answered Sep 17 '22 04:09

Chris J