/// <summary> /// Checks if the dead key is down. /// If there is multiple dead keys, drop the action. /// </summary> /// <returns><c>true</c>, if dead key is down, <c>false</c> otherwise.</returns> /// <param name="keyboardState">Keyboard state.</param> /// <param name="deadKey">Dead key.</param> bool CheckDeadKey(KeyboardState keyboardState, DeadKeys deadKey) { bool altDown = keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt); bool shiftDown = keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift); bool controlDown = keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.LeftControl); if (deadKey == DeadKeys.None) { if (!altDown && !shiftDown && !controlDown) { return(true); } return(false); } // Makes sure there is only one dead key pressed. if (altDown ? (!shiftDown && !controlDown) : (shiftDown ^ controlDown)) { switch (deadKey) { case DeadKeys.Alt: if (altDown) { return(true); } break; case DeadKeys.Shift: if (shiftDown) { return(true); } break; case DeadKeys.Control: if (controlDown) { return(true); } break; case DeadKeys.None: return(true); } } return(false); }
/// <summary> /// Checks if the dead key is down. /// If there is multiple dead keys, drop the action. /// </summary> /// <returns><c>true</c>, if dead key is down, <c>false</c> otherwise.</returns> /// <param name="keyboardState">Keyboard state.</param> /// <param name="deadKey">Dead key.</param> bool CheckDeadKey(KeyboardState keyboardState, DeadKeys deadKey) { bool altDown = keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt); bool shiftDown = keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift); bool controlDown = keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.LeftControl); if (deadKey == DeadKeys.None) { if (!altDown && !shiftDown && !controlDown) { return true; } return false; } // Makes sure there is only one dead key pressed. if (altDown ? (!shiftDown && !controlDown) : (shiftDown ^ controlDown)) { switch (deadKey) { case DeadKeys.Alt: if (altDown) { return true; } break; case DeadKeys.Shift: if (shiftDown) { return true; } break; case DeadKeys.Control: if (controlDown) { return true; } break; case DeadKeys.None: return true; } } return false; }