No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 8 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // This code is distributed under MIT license.
  2. // Copyright (c) 2010-2018 George Mamaladze
  3. // See license.txt or https://mit-license.org/
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. namespace Gma.System.MouseKeyHook.Implementation
  10. {
  11. internal class Chord : IEnumerable<Keys>
  12. {
  13. private readonly Keys[] _keys;
  14. internal Chord(IEnumerable<Keys> additionalKeys)
  15. {
  16. _keys = additionalKeys.Select(k => k.Normalize()).OrderBy(k => k).ToArray();
  17. }
  18. public int Count
  19. {
  20. get { return _keys.Length; }
  21. }
  22. public IEnumerator<Keys> GetEnumerator()
  23. {
  24. return _keys.Cast<Keys>().GetEnumerator();
  25. }
  26. IEnumerator IEnumerable.GetEnumerator()
  27. {
  28. return GetEnumerator();
  29. }
  30. public override string ToString()
  31. {
  32. return string.Join("+", _keys);
  33. }
  34. public static Chord FromString(string chord)
  35. {
  36. var parts = chord
  37. .Split('+')
  38. .Select(p => Enum.Parse(typeof(Keys), p))
  39. .Cast<Keys>();
  40. var stack = new Stack<Keys>(parts);
  41. return new Chord(stack);
  42. }
  43. protected bool Equals(Chord other)
  44. {
  45. if (_keys.Length != other._keys.Length) return false;
  46. return _keys.SequenceEqual(other._keys);
  47. }
  48. public override bool Equals(object obj)
  49. {
  50. if (ReferenceEquals(null, obj)) return false;
  51. if (ReferenceEquals(this, obj)) return true;
  52. if (obj.GetType() != GetType()) return false;
  53. return Equals((Chord) obj);
  54. }
  55. public override int GetHashCode()
  56. {
  57. unchecked
  58. {
  59. return (_keys.Length + 13) ^
  60. ((_keys.Length != 0 ? (int) _keys[0] ^ (int) _keys[_keys.Length - 1] : 0) * 397);
  61. }
  62. }
  63. }
  64. }