=> Assert.Equal(expected, MyCommon.IsValidEmail(email));
[Theory]
- [InlineData(Keys.Shift, new[] { Keys.Shift }, true)]
- [InlineData(Keys.Shift, new[] { Keys.Control }, false)]
- [InlineData(Keys.Control | Keys.Alt, new[] { Keys.Control }, true)]
- [InlineData(Keys.Control | Keys.Alt, new[] { Keys.Alt }, true)]
- [InlineData(Keys.Control | Keys.Alt, new[] { Keys.Control, Keys.Alt }, true)]
- [InlineData(Keys.Control | Keys.Alt, new[] { Keys.Shift }, false)]
- public void IsKeyDownTest(Keys modifierKeys, Keys[] checkKeys, bool expected)
- => Assert.Equal(expected, MyCommon.IsKeyDownInternal(modifierKeys, checkKeys));
+ [InlineData(Keys.Shift, Keys.Shift, true)]
+ [InlineData(Keys.Shift, Keys.Control, false)]
+ [InlineData(Keys.Control | Keys.Alt, Keys.Control, true)]
+ [InlineData(Keys.Control | Keys.Alt, Keys.Alt, true)]
+ [InlineData(Keys.Control | Keys.Alt, Keys.Control | Keys.Alt, true)]
+ [InlineData(Keys.Control | Keys.Alt, Keys.Shift, false)]
+ public void IsKeyDownTest(Keys modifierKeys, Keys checkKeys, bool expected)
+ => Assert.Equal(expected, MyCommon.IsKeyDown(modifierKeys, checkKeys));
[Fact]
public void GetAssemblyNameTest()
/// </summary>
/// <param name="keys">状態を調べるキー</param>
/// <returns><paramref name="keys"/> で指定された修飾キーがすべて押されている状態であれば true。それ以外であれば false。</returns>
- public static bool IsKeyDown(params Keys[] keys)
- => MyCommon.IsKeyDownInternal(Control.ModifierKeys, keys);
+ public static bool IsKeyDown(Keys keys)
+ => MyCommon.IsKeyDown(Control.ModifierKeys, keys);
- internal static bool IsKeyDownInternal(Keys modifierKeys, Keys[] targetKeys)
- {
- foreach (var key in targetKeys)
- {
- if ((modifierKeys & key) != key)
- {
- return false;
- }
- }
- return true;
- }
+ public static bool IsKeyDown(Keys modifierKeys, Keys targetKeys)
+ => (modifierKeys & targetKeys) == targetKeys;
/// <summary>
/// アプリケーションのアセンブリ名を取得します。
private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
{
- if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
+ if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock | Keys.Control | Keys.Shift))
this.DebugModeToolStripMenuItem.Visible = true;
else
this.DebugModeToolStripMenuItem.Visible = false;