JD2022-TU1/main/tools/framework/JD.Core/KeyWithModifier.cs

56 lines
1.4 KiB
C#

using System;
using System.Windows.Input;
using JD.Interfaces;
namespace JD.Core
{
public class KeyWithModifier : IEquatable<KeyWithModifier>, IKeyWithModifier
{
private readonly Key _key;
private readonly ModifierKeys _modifiers;
public KeyWithModifier(Key key, ModifierKeys modifiers = ModifierKeys.None)
{
_key = key;
_modifiers = modifiers;
}
public Key Key => _key;
public ModifierKeys Modifiers => _modifiers;
public static bool operator ==(KeyWithModifier first, KeyWithModifier second)
{
if ((object)first == null)
{
if ((object)second == null)
return true;
else
return false;
}
return first.Equals(second);
}
public static bool operator !=(KeyWithModifier first, KeyWithModifier second)
{
return !(first == second);
}
public override bool Equals(object obj)
{
if (!(obj is KeyWithModifier))
return false;
return Equals((KeyWithModifier)obj);
}
public bool Equals(KeyWithModifier other)
{
return (_key == other._key && _modifiers == other._modifiers);
}
public override int GetHashCode()
{
return (int)_modifiers << 16 + (int)_key;
}
}
}