using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Gma.System.MouseKeyHook.Implementation;
using Gma.System.MouseKeyHook.WinApi;
using Microsoft.Win32.SafeHandles;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MouseKeyHook")]
[assembly: AssemblyDescription("This library allows you to tap keyboard and mouse, to detect and record their activity even when an application is inactive and runs in background.")]
[assembly: AssemblyCopyright("(c) George Mamaladze 2000-2018")]
[assembly: ComVisible(false)]
[assembly: TargetFramework(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
[assembly: AssemblyVersion("5.6.130.0")]
namespace Gma.System.MouseKeyHook
{
	public static class KeyCombinationExtensions
	{
		public static void OnCombination(this IKeyboardEvents source, IEnumerable<KeyValuePair<Combination, Action>> map, Action reset = null)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			Dictionary<Keys, KeyValuePair<Combination, Action>[]> watchlists = (from k in map
				group k by k.Key.TriggerKey).ToDictionary((IGrouping<Keys, KeyValuePair<Combination, Action>> g) => g.Key, (IGrouping<Keys, KeyValuePair<Combination, Action>> g) => g.ToArray());
			source.KeyDown += (KeyEventHandler)delegate(object sender, KeyEventArgs e)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				if (!watchlists.TryGetValue(e.KeyCode, out var value))
				{
					reset?.Invoke();
				}
				else
				{
					KeyboardState current = KeyboardState.GetCurrent();
					Action action = reset;
					int num = 0;
					KeyValuePair<Combination, Action>[] array = value;
					for (int i = 0; i < array.Length; i++)
					{
						KeyValuePair<Combination, Action> keyValuePair = array[i];
						if (keyValuePair.Key.Chord.All(current.IsDown) && num <= keyValuePair.Key.ChordLength)
						{
							num = keyValuePair.Key.ChordLength;
							action = keyValuePair.Value;
						}
					}
					action?.Invoke();
				}
			};
		}

		public static void OnSequence(this IKeyboardEvents source, IEnumerable<KeyValuePair<Sequence, Action>> map)
		{
			KeyValuePair<Sequence, Action>[] actBySeq = map.ToArray();
			Func<Queue<Combination>, Sequence, bool> endsWith = delegate(Queue<Combination> chords, Sequence sequence)
			{
				int num = chords.Count - sequence.Length;
				return num >= 0 && chords.Skip(num).SequenceEqual(sequence);
			};
			int max = actBySeq.Select((KeyValuePair<Sequence, Action> p) => p.Key).Max((Sequence c) => c.Length);
			int min = actBySeq.Select((KeyValuePair<Sequence, Action> p) => p.Key).Min((Sequence c) => c.Length);
			Queue<Combination> buffer = new Queue<Combination>(max);
			IEnumerable<KeyValuePair<Combination, Action>> map2 = from c in actBySeq.SelectMany((KeyValuePair<Sequence, Action> p) => p.Key)
				select new KeyValuePair<Combination, Action>(c, delegate
				{
					buffer.Enqueue(c);
					if (buffer.Count > max)
					{
						buffer.Dequeue();
					}
					if (buffer.Count >= min)
					{
						(from pair in actBySeq
							where endsWith(buffer, pair.Key)
							orderby pair.Key.Length
							select pair.Value).LastOrDefault()?.Invoke();
					}
				});
			source.OnCombination(map2, buffer.Clear);
		}
	}
	public static class Hook
	{
		public static IKeyboardMouseEvents AppEvents()
		{
			return new AppEventFacade();
		}

		public static IKeyboardMouseEvents GlobalEvents()
		{
			return new GlobalEventFacade();
		}
	}
	public interface IKeyboardMouseEvents : IKeyboardEvents, IMouseEvents, IDisposable
	{
	}
	public interface IMouseEvents
	{
		event MouseEventHandler MouseMove;

		event EventHandler<MouseEventExtArgs> MouseMoveExt;

		event MouseEventHandler MouseClick;

		event MouseEventHandler MouseDown;

		event EventHandler<MouseEventExtArgs> MouseDownExt;

		event MouseEventHandler MouseUp;

		event EventHandler<MouseEventExtArgs> MouseUpExt;

		event MouseEventHandler MouseWheel;

		event EventHandler<MouseEventExtArgs> MouseWheelExt;

		event MouseEventHandler MouseDoubleClick;

		event MouseEventHandler MouseDragStarted;

		event EventHandler<MouseEventExtArgs> MouseDragStartedExt;

		event MouseEventHandler MouseDragFinished;

		event EventHandler<MouseEventExtArgs> MouseDragFinishedExt;
	}
	public interface IKeyboardEvents
	{
		event KeyEventHandler KeyDown;

		event KeyPressEventHandler KeyPress;

		event KeyEventHandler KeyUp;
	}
	public class KeyPressEventArgsExt : KeyPressEventArgs
	{
		public bool IsNonChar { get; }

		public int Timestamp { get; }

		internal KeyPressEventArgsExt(char keyChar, int timestamp)
			: base(keyChar)
		{
			IsNonChar = keyChar == '\0';
			Timestamp = timestamp;
		}

		public KeyPressEventArgsExt(char keyChar)
			: this(keyChar, Environment.TickCount)
		{
		}

		internal static IEnumerable<KeyPressEventArgsExt> FromRawDataApp(CallbackData data)
		{
			IntPtr wParam = data.WParam;
			uint flags = (uint)data.LParam.ToInt64();
			bool wasKeyDown = (flags & 0x40000000) != 0;
			bool isKeyReleased = (flags & 0x80000000u) != 0;
			if (!wasKeyDown && !isKeyReleased)
			{
				yield break;
			}
			int virtualKeyCode = (int)wParam;
			int scanCode = checked((int)(flags & 0xFF0000));
			KeyboardNativeMethods.TryGetCharFromKeyboardState(virtualKeyCode, scanCode, 0, out var chars);
			if (chars != null)
			{
				char[] array = chars;
				foreach (char ch in array)
				{
					yield return new KeyPressEventArgsExt(ch);
				}
			}
		}

		internal static IEnumerable<KeyPressEventArgsExt> FromRawDataGlobal(CallbackData data)
		{
			IntPtr wParam = data.WParam;
			IntPtr lParam = data.LParam;
			if ((int)wParam != 256 && (int)wParam != 260)
			{
				yield break;
			}
			KeyboardHookStruct keyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
			int virtualKeyCode = keyboardHookStruct.VirtualKeyCode;
			int scanCode = keyboardHookStruct.ScanCode;
			int fuState = keyboardHookStruct.Flags;
			if (virtualKeyCode == 231)
			{
				char ch = (char)scanCode;
				yield return new KeyPressEventArgsExt(ch, keyboardHookStruct.Time);
				yield break;
			}
			KeyboardNativeMethods.TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, out var chars);
			if (chars != null)
			{
				char[] array = chars;
				foreach (char current in array)
				{
					yield return new KeyPressEventArgsExt(current, keyboardHookStruct.Time);
				}
			}
		}
	}
	public class Sequence : SequenceBase<Combination>
	{
		private Sequence(Combination[] combinations)
			: base(combinations)
		{
		}

		public static Sequence Of(params Combination[] combinations)
		{
			return new Sequence(combinations);
		}

		public static Sequence FromString(string text)
		{
			string[] source = text.Split(new char[1] { ',' });
			Combination[] combinations = source.Select(Combination.FromString).ToArray();
			return new Sequence(combinations);
		}
	}
	public abstract class SequenceBase<T> : IEnumerable<T>, IEnumerable
	{
		private readonly T[] _elements;

		public int Length => _elements.Length;

		protected SequenceBase(params T[] elements)
		{
			_elements = elements;
		}

		public IEnumerator<T> GetEnumerator()
		{
			return _elements.Cast<T>().GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public override string ToString()
		{
			return string.Join(",", _elements);
		}

		protected bool Equals(SequenceBase<T> other)
		{
			if (_elements.Length != other._elements.Length)
			{
				return false;
			}
			return Enumerable.SequenceEqual(_elements, other._elements);
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (this == obj)
			{
				return true;
			}
			if (obj.GetType() != GetType())
			{
				return false;
			}
			return Equals((Combination)obj);
		}

		public override int GetHashCode()
		{
			return (_elements.Length + 13) ^ (((_elements.Length != 0) ? (_elements[0].GetHashCode() ^ _elements[_elements.Length - 1].GetHashCode()) : 0) * 397);
		}
	}
	public class Combination
	{
		private readonly Chord _chord;

		public Keys TriggerKey { get; }

		public IEnumerable<Keys> Chord => _chord;

		public int ChordLength => _chord.Count;

		private Combination(Keys triggerKey, IEnumerable<Keys> chordKeys)
			: this(triggerKey, new Chord(chordKeys))
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)


		private Combination(Keys triggerKey, Chord chord)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			TriggerKey = triggerKey.Normalize();
			_chord = chord;
		}

		public static Combination TriggeredBy(Keys key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return new Combination(key, (IEnumerable<Keys>)new Chord(Enumerable.Empty<Keys>()));
		}

		public Combination With(Keys key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return new Combination(TriggerKey, Chord.Concat(Enumerable.Repeat<Keys>(key, 1)));
		}

		public Combination Control()
		{
			return With((Keys)131072);
		}

		public Combination Alt()
		{
			return With((Keys)262144);
		}

		public Combination Shift()
		{
			return With((Keys)65536);
		}

		public override string ToString()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return string.Join("+", Chord.Concat(Enumerable.Repeat<Keys>(TriggerKey, 1)));
		}

		public static Combination FromString(string trigger)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			IEnumerable<Keys> collection = (from p in trigger.Split(new char[1] { '+' })
				select Enum.Parse(typeof(Keys), p)).Cast<Keys>();
			Stack<Keys> stack = new Stack<Keys>(collection);
			Keys triggerKey = stack.Pop();
			return new Combination(triggerKey, stack);
		}

		protected bool Equals(Combination other)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return TriggerKey == other.TriggerKey && Chord.Equals(other.Chord);
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (this == obj)
			{
				return true;
			}
			if (obj.GetType() != GetType())
			{
				return false;
			}
			return Equals((Combination)obj);
		}

		public override int GetHashCode()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected I4, but got Unknown
			return Chord.GetHashCode() ^ TriggerKey;
		}
	}
	public class KeyEventArgsExt : KeyEventArgs
	{
		public int ScanCode { get; }

		public int Timestamp { get; }

		public bool IsKeyDown { get; }

		public bool IsKeyUp { get; }

		public bool IsExtendedKey { get; }

		public KeyEventArgsExt(Keys keyData)
			: base(keyData)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)


		internal KeyEventArgsExt(Keys keyData, int scanCode, int timestamp, bool isKeyDown, bool isKeyUp, bool isExtendedKey)
			: this(keyData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			ScanCode = scanCode;
			Timestamp = timestamp;
			IsKeyDown = isKeyDown;
			IsKeyUp = isKeyUp;
			IsExtendedKey = isExtendedKey;
		}

		internal static KeyEventArgsExt FromRawDataApp(CallbackData data)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			IntPtr wParam = data.WParam;
			IntPtr lParam = data.LParam;
			int tickCount = Environment.TickCount;
			uint num = (uint)lParam.ToInt64();
			bool flag = (num & 0x40000000) != 0;
			bool flag2 = (num & 0x80000000u) != 0;
			bool isExtendedKey = (num & 0x1000000) != 0;
			Keys keyData = AppendModifierStates((Keys)(int)wParam);
			int scanCode = (int)(((num & 0x10000) | (num & 0x20000) | (num & 0x40000) | (num & 0x80000) | (num & 0x100000) | (num & 0x200000) | (num & 0x400000) | (num & 0x800000)) >> 16);
			bool isKeyDown = !flag2;
			bool isKeyUp = flag && flag2;
			return new KeyEventArgsExt(keyData, scanCode, tickCount, isKeyDown, isKeyUp, isExtendedKey);
		}

		internal static KeyEventArgsExt FromRawDataGlobal(CallbackData data)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			IntPtr wParam = data.WParam;
			IntPtr lParam = data.LParam;
			KeyboardHookStruct keyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
			Keys keyData = AppendModifierStates((Keys)keyboardHookStruct.VirtualKeyCode);
			int num = (int)wParam;
			bool isKeyDown = num == 256 || num == 260;
			bool isKeyUp = num == 257 || num == 261;
			bool isExtendedKey = (long)((ulong)keyboardHookStruct.Flags & 1uL) > 0L;
			return new KeyEventArgsExt(keyData, keyboardHookStruct.ScanCode, keyboardHookStruct.Time, isKeyDown, isKeyUp, isExtendedKey);
		}

		private static bool CheckModifier(int vKey)
		{
			return (KeyboardNativeMethods.GetKeyState(vKey) & 0x8000) > 0;
		}

		private static Keys AppendModifierStates(Keys keyData)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			bool flag = CheckModifier(17);
			bool flag2 = CheckModifier(16);
			bool flag3 = CheckModifier(18);
			return (Keys)(keyData | (flag ? 131072 : 0) | (flag2 ? 65536 : 0) | (flag3 ? 262144 : 0));
		}
	}
	public class MouseEventExtArgs : MouseEventArgs
	{
		public bool Handled { get; set; }

		public bool WheelScrolled => ((MouseEventArgs)this).Delta != 0;

		public bool Clicked => ((MouseEventArgs)this).Clicks > 0;

		public bool IsMouseButtonDown { get; }

		public bool IsMouseButtonUp { get; }

		public int Timestamp { get; }

		internal Point Point => new Point(((MouseEventArgs)this).X, ((MouseEventArgs)this).Y);

		internal MouseEventExtArgs(MouseButtons buttons, int clicks, Point point, int delta, int timestamp, bool isMouseButtonDown, bool isMouseButtonUp)
			: base(buttons, clicks, point.X, point.Y, delta)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			IsMouseButtonDown = isMouseButtonDown;
			IsMouseButtonUp = isMouseButtonUp;
			Timestamp = timestamp;
		}

		internal static MouseEventExtArgs FromRawDataApp(CallbackData data)
		{
			IntPtr wParam = data.WParam;
			IntPtr lParam = data.LParam;
			return FromRawDataUniversal(wParam, ((AppMouseStruct)Marshal.PtrToStructure(lParam, typeof(AppMouseStruct))).ToMouseStruct());
		}

		internal static MouseEventExtArgs FromRawDataGlobal(CallbackData data)
		{
			IntPtr wParam = data.WParam;
			IntPtr lParam = data.LParam;
			MouseStruct mouseInfo = (MouseStruct)Marshal.PtrToStructure(lParam, typeof(MouseStruct));
			return FromRawDataUniversal(wParam, mouseInfo);
		}

		private static MouseEventExtArgs FromRawDataUniversal(IntPtr wParam, MouseStruct mouseInfo)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			MouseButtons buttons = (MouseButtons)0;
			short delta = 0;
			int clicks = 0;
			bool isMouseButtonDown = false;
			bool isMouseButtonUp = false;
			long num = (long)wParam;
			long num2 = num - 513;
			if ((ulong)num2 <= 13uL)
			{
				switch ((int)num2)
				{
				case 0:
					isMouseButtonDown = true;
					buttons = (MouseButtons)1048576;
					clicks = 1;
					break;
				case 1:
					isMouseButtonUp = true;
					buttons = (MouseButtons)1048576;
					clicks = 1;
					break;
				case 2:
					isMouseButtonDown = true;
					buttons = (MouseButtons)1048576;
					clicks = 2;
					break;
				case 3:
					isMouseButtonDown = true;
					buttons = (MouseButtons)2097152;
					clicks = 1;
					break;
				case 4:
					isMouseButtonUp = true;
					buttons = (MouseButtons)2097152;
					clicks = 1;
					break;
				case 5:
					isMouseButtonDown = true;
					buttons = (MouseButtons)2097152;
					clicks = 2;
					break;
				case 6:
					isMouseButtonDown = true;
					buttons = (MouseButtons)4194304;
					clicks = 1;
					break;
				case 7:
					isMouseButtonUp = true;
					buttons = (MouseButtons)4194304;
					clicks = 1;
					break;
				case 8:
					isMouseButtonDown = true;
					buttons = (MouseButtons)4194304;
					clicks = 2;
					break;
				case 9:
					delta = mouseInfo.MouseData;
					break;
				case 10:
					buttons = (MouseButtons)((mouseInfo.MouseData == 1) ? 8388608 : 16777216);
					isMouseButtonDown = true;
					clicks = 1;
					break;
				case 11:
					buttons = (MouseButtons)((mouseInfo.MouseData == 1) ? 8388608 : 16777216);
					isMouseButtonUp = true;
					clicks = 1;
					break;
				case 12:
					isMouseButtonDown = true;
					buttons = (MouseButtons)((mouseInfo.MouseData == 1) ? 8388608 : 16777216);
					clicks = 2;
					break;
				case 13:
					delta = mouseInfo.MouseData;
					break;
				}
			}
			return new MouseEventExtArgs(buttons, clicks, mouseInfo.Point, delta, mouseInfo.Timestamp, isMouseButtonDown, isMouseButtonUp);
		}

		internal MouseEventExtArgs ToDoubleClickEventArgs()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return new MouseEventExtArgs(((MouseEventArgs)this).Button, 2, Point, ((MouseEventArgs)this).Delta, Timestamp, IsMouseButtonDown, IsMouseButtonUp);
		}
	}
}
namespace Gma.System.MouseKeyHook.HotKeys
{
	public sealed class HotKeyArgs : EventArgs
	{
		public DateTime Time { get; }

		public HotKeyArgs(DateTime triggeredAt)
		{
			Time = triggeredAt;
		}
	}
	public class HotKeySet
	{
		public delegate void HotKeyHandler(object sender, HotKeyArgs e);

		private readonly Dictionary<Keys, bool> m_hotkeystate;

		private readonly Dictionary<Keys, Keys> m_remapping;

		private bool m_enabled = true;

		private int m_hotkeydowncount;

		private int m_remappingCount;

		public string Name { get; set; }

		public string Description { get; set; }

		public IEnumerable<Keys> HotKeys { get; }

		public bool HotKeysActivated => m_hotkeydowncount == m_hotkeystate.Count - m_remappingCount;

		public bool Enabled
		{
			get
			{
				return m_enabled;
			}
			set
			{
				if (value)
				{
					InitializeKeys();
				}
				m_enabled = value;
			}
		}

		public event HotKeyHandler OnHotKeysDownHold;

		public event HotKeyHandler OnHotKeysUp;

		public event HotKeyHandler OnHotKeysDownOnce;

		public HotKeySet(IEnumerable<Keys> hotkeys)
		{
			m_hotkeystate = new Dictionary<Keys, bool>();
			m_remapping = new Dictionary<Keys, Keys>();
			HotKeys = hotkeys;
			InitializeKeys();
		}

		private void InvokeHotKeyHandler(HotKeyHandler hotKeyDelegate)
		{
			hotKeyDelegate?.Invoke(this, new HotKeyArgs(DateTime.Now));
		}

		private void InitializeKeys()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			foreach (Keys hotKey in HotKeys)
			{
				if (m_hotkeystate.ContainsKey(hotKey))
				{
					m_hotkeystate.Add(hotKey, value: false);
				}
				m_hotkeystate[hotKey] = KeyboardState.GetCurrent().IsDown(hotKey);
			}
		}

		public bool UnregisterExclusiveOrKey(Keys anyKeyInTheExclusiveOrSet)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			Keys exclusiveOrPrimaryKey = GetExclusiveOrPrimaryKey(anyKeyInTheExclusiveOrSet);
			if ((int)exclusiveOrPrimaryKey == 0 || !m_remapping.ContainsValue(exclusiveOrPrimaryKey))
			{
				return false;
			}
			List<Keys> list = new List<Keys>();
			foreach (KeyValuePair<Keys, Keys> item in m_remapping)
			{
				if (item.Value == exclusiveOrPrimaryKey)
				{
					list.Add(item.Key);
				}
			}
			foreach (Keys item2 in list)
			{
				m_remapping.Remove(item2);
			}
			m_remappingCount--;
			return true;
		}

		public Keys RegisterExclusiveOrKey(IEnumerable<Keys> orKeySet)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			foreach (Keys item in orKeySet)
			{
				if (!m_hotkeystate.ContainsKey(item))
				{
					return (Keys)0;
				}
			}
			int num = 0;
			Keys val = (Keys)0;
			foreach (Keys item2 in orKeySet)
			{
				if (num == 0)
				{
					val = item2;
				}
				m_remapping[item2] = val;
				num++;
			}
			m_remappingCount++;
			return val;
		}

		private Keys GetExclusiveOrPrimaryKey(Keys k)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return (Keys)(m_remapping.ContainsKey(k) ? ((int)m_remapping[k]) : 0);
		}

		private Keys GetPrimaryKey(Keys k)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return m_remapping.ContainsKey(k) ? m_remapping[k] : k;
		}

		internal void OnKey(KeyEventArgsExt kex)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled)
			{
				Keys primaryKey = GetPrimaryKey(((KeyEventArgs)kex).KeyCode);
				if (kex.IsKeyDown)
				{
					OnKeyDown(primaryKey);
				}
				else
				{
					OnKeyUp(primaryKey);
				}
			}
		}

		private void OnKeyDown(Keys k)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (HotKeysActivated)
			{
				InvokeHotKeyHandler(this.OnHotKeysDownHold);
			}
			else if (m_hotkeystate.ContainsKey(k) && !m_hotkeystate[k])
			{
				m_hotkeystate[k] = true;
				m_hotkeydowncount++;
				if (HotKeysActivated)
				{
					InvokeHotKeyHandler(this.OnHotKeysDownOnce);
				}
			}
		}

		private void OnKeyUp(Keys k)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (m_hotkeystate.ContainsKey(k) && m_hotkeystate[k])
			{
				bool hotKeysActivated = HotKeysActivated;
				m_hotkeystate[k] = false;
				m_hotkeydowncount--;
				if (hotKeysActivated)
				{
					InvokeHotKeyHandler(this.OnHotKeysUp);
				}
			}
		}
	}
	public sealed class HotKeySetCollection : List<HotKeySet>
	{
		private delegate void KeyChainHandler(KeyEventArgsExt kex);

		private KeyChainHandler m_keyChain;

		public new void Add(HotKeySet hks)
		{
			m_keyChain = (KeyChainHandler)Delegate.Combine(m_keyChain, new KeyChainHandler(hks.OnKey));
			base.Add(hks);
		}

		public new void Remove(HotKeySet hks)
		{
			m_keyChain = (KeyChainHandler)Delegate.Remove(m_keyChain, new KeyChainHandler(hks.OnKey));
			base.Remove(hks);
		}

		internal void OnKey(KeyEventArgsExt e)
		{
			if (m_keyChain != null)
			{
				m_keyChain(e);
			}
		}
	}
}
namespace Gma.System.MouseKeyHook.WinApi
{
	[StructLayout(LayoutKind.Explicit)]
	internal struct AppMouseStruct
	{
		[FieldOffset(0)]
		public Point Point;

		[FieldOffset(22)]
		public short MouseData_x86;

		[FieldOffset(34)]
		public short MouseData_x64;

		public MouseStruct ToMouseStruct()
		{
			return new MouseStruct
			{
				Point = Point,
				MouseData = ((IntPtr.Size == 4) ? MouseData_x86 : MouseData_x64),
				Timestamp = Environment.TickCount
			};
		}
	}
	internal struct CallbackData(IntPtr wParam, IntPtr lParam)
	{
		public IntPtr WParam { get; } = wParam;

		public IntPtr LParam { get; } = lParam;
	}
	internal static class HookHelper
	{
		private static HookProcedure _appHookProc;

		private static HookProcedure _globalHookProc;

		public static HookResult HookAppMouse(Callback callback)
		{
			return HookApp(7, callback);
		}

		public static HookResult HookAppKeyboard(Callback callback)
		{
			return HookApp(2, callback);
		}

		public static HookResult HookGlobalMouse(Callback callback)
		{
			return HookGlobal(14, callback);
		}

		public static HookResult HookGlobalKeyboard(Callback callback)
		{
			return HookGlobal(13, callback);
		}

		private static HookResult HookApp(int hookId, Callback callback)
		{
			_appHookProc = (int code, IntPtr param, IntPtr lParam) => HookProcedure(code, param, lParam, callback);
			HookProcedureHandle hookProcedureHandle = HookNativeMethods.SetWindowsHookEx(hookId, _appHookProc, IntPtr.Zero, ThreadNativeMethods.GetCurrentThreadId());
			if (hookProcedureHandle.IsInvalid)
			{
				ThrowLastUnmanagedErrorAsException();
			}
			return new HookResult(hookProcedureHandle, _appHookProc);
		}

		private static HookResult HookGlobal(int hookId, Callback callback)
		{
			_globalHookProc = (int code, IntPtr param, IntPtr lParam) => HookProcedure(code, param, lParam, callback);
			HookProcedureHandle hookProcedureHandle = HookNativeMethods.SetWindowsHookEx(hookId, _globalHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);
			if (hookProcedureHandle.IsInvalid)
			{
				ThrowLastUnmanagedErrorAsException();
			}
			return new HookResult(hookProcedureHandle, _globalHookProc);
		}

		private static IntPtr HookProcedure(int nCode, IntPtr wParam, IntPtr lParam, Callback callback)
		{
			if (nCode != 0)
			{
				return CallNextHookEx(nCode, wParam, lParam);
			}
			CallbackData data = new CallbackData(wParam, lParam);
			if (!callback(data))
			{
				return new IntPtr(-1);
			}
			return CallNextHookEx(nCode, wParam, lParam);
		}

		private static IntPtr CallNextHookEx(int nCode, IntPtr wParam, IntPtr lParam)
		{
			return HookNativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
		}

		private static void ThrowLastUnmanagedErrorAsException()
		{
			int lastWin32Error = Marshal.GetLastWin32Error();
			throw new Win32Exception(lastWin32Error);
		}
	}
	internal static class HookIds
	{
		internal const int WH_MOUSE = 7;

		internal const int WH_KEYBOARD = 2;

		internal const int WH_MOUSE_LL = 14;

		internal const int WH_KEYBOARD_LL = 13;
	}
	internal static class HookNativeMethods
	{
		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
		internal static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern HookProcedureHandle SetWindowsHookEx(int idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId);

		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern int UnhookWindowsHookEx(IntPtr idHook);
	}
	internal class HookProcedureHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		private static bool _closing;

		static HookProcedureHandle()
		{
			Application.ApplicationExit += delegate
			{
				_closing = true;
			};
		}

		public HookProcedureHandle()
			: base(ownsHandle: true)
		{
		}

		protected override bool ReleaseHandle()
		{
			if (_closing)
			{
				return true;
			}
			return HookNativeMethods.UnhookWindowsHookEx(handle) != 0;
		}
	}
	internal class HookResult : IDisposable
	{
		public HookProcedureHandle Handle { get; }

		public HookProcedure Procedure { get; }

		public HookResult(HookProcedureHandle handle, HookProcedure procedure)
		{
			Handle = handle;
			Procedure = procedure;
		}

		public void Dispose()
		{
			Handle.Dispose();
		}
	}
	internal static class HotkeysNativeMethods
	{
		[DllImport("user32.dll")]
		public static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);

		[DllImport("user32.dll")]
		public static extern bool UnregisterHotKey(IntPtr hwnd, int id);
	}
	internal static class MouseNativeMethods
	{
		[DllImport("user32")]
		internal static extern int GetDoubleClickTime();
	}
	[StructLayout(LayoutKind.Explicit)]
	internal struct MouseStruct
	{
		[FieldOffset(0)]
		public Point Point;

		[FieldOffset(10)]
		public short MouseData;

		[FieldOffset(16)]
		public int Timestamp;
	}
	internal struct KeyboardHookStruct
	{
		public int VirtualKeyCode;

		public int ScanCode;

		public int Flags;

		public int Time;

		public int ExtraInfo;
	}
	internal struct Point(int x, int y)
	{
		public int X = x;

		public int Y = y;

		public static bool operator ==(Point a, Point b)
		{
			return a.X == b.X && a.Y == b.Y;
		}

		public static bool operator !=(Point a, Point b)
		{
			return !(a == b);
		}

		public bool Equals(Point other)
		{
			return other.X == X && other.Y == Y;
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (obj.GetType() != typeof(Point))
			{
				return false;
			}
			return Equals((Point)obj);
		}

		public override int GetHashCode()
		{
			return (X * 397) ^ Y;
		}
	}
	public delegate IntPtr HookProcedure(int nCode, IntPtr wParam, IntPtr lParam);
	internal static class KeyboardNativeMethods
	{
		internal enum MapType
		{
			MAPVK_VK_TO_VSC,
			MAPVK_VSC_TO_VK,
			MAPVK_VK_TO_CHAR,
			MAPVK_VSC_TO_VK_EX
		}

		public const byte VK_SHIFT = 16;

		public const byte VK_CAPITAL = 20;

		public const byte VK_NUMLOCK = 144;

		public const byte VK_LSHIFT = 160;

		public const byte VK_RSHIFT = 161;

		public const byte VK_LCONTROL = 162;

		public const byte VK_RCONTROL = 163;

		public const byte VK_LMENU = 164;

		public const byte VK_RMENU = 165;

		public const byte VK_LWIN = 91;

		public const byte VK_RWIN = 92;

		public const byte VK_SCROLL = 145;

		public const byte VK_INSERT = 45;

		public const byte VK_CONTROL = 17;

		public const byte VK_MENU = 18;

		public const byte VK_PACKET = 231;

		private static int lastVirtualKeyCode;

		private static int lastScanCode;

		private static byte[] lastKeyState = new byte[255];

		private static bool lastIsDead;

		internal static void TryGetCharFromKeyboardState(int virtualKeyCode, int fuState, out char[] chars)
		{
			IntPtr activeKeyboard = GetActiveKeyboard();
			int scanCode = MapVirtualKeyEx(virtualKeyCode, 0, activeKeyboard);
			TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, activeKeyboard, out chars);
		}

		internal static void TryGetCharFromKeyboardState(int virtualKeyCode, int scanCode, int fuState, out char[] chars)
		{
			IntPtr activeKeyboard = GetActiveKeyboard();
			TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, activeKeyboard, out chars);
		}

		internal static void TryGetCharFromKeyboardState(int virtualKeyCode, int scanCode, int fuState, IntPtr dwhkl, out char[] chars)
		{
			StringBuilder stringBuilder = new StringBuilder(64);
			KeyboardState current = KeyboardState.GetCurrent();
			byte[] nativeState = current.GetNativeState();
			bool flag = false;
			if (current.IsDown((Keys)16))
			{
				nativeState[16] = 128;
			}
			if (current.IsToggled((Keys)20))
			{
				nativeState[20] = 1;
			}
			switch (ToUnicodeEx(virtualKeyCode, scanCode, nativeState, stringBuilder, stringBuilder.Capacity, fuState, dwhkl))
			{
			case -1:
				flag = true;
				ClearKeyboardBuffer(virtualKeyCode, scanCode, dwhkl);
				chars = null;
				break;
			case 0:
				chars = null;
				break;
			case 1:
				if (stringBuilder.Length > 0)
				{
					chars = new char[1] { stringBuilder[0] };
				}
				else
				{
					chars = null;
				}
				break;
			default:
				if (stringBuilder.Length > 1)
				{
					chars = new char[2]
					{
						stringBuilder[0],
						stringBuilder[1]
					};
				}
				else
				{
					chars = new char[1] { stringBuilder[0] };
				}
				break;
			}
			if (lastVirtualKeyCode != 0 && lastIsDead)
			{
				if (chars != null)
				{
					StringBuilder stringBuilder2 = new StringBuilder(5);
					ToUnicodeEx(lastVirtualKeyCode, lastScanCode, lastKeyState, stringBuilder2, stringBuilder2.Capacity, 0, dwhkl);
					lastIsDead = false;
					lastVirtualKeyCode = 0;
				}
			}
			else
			{
				lastScanCode = scanCode;
				lastVirtualKeyCode = virtualKeyCode;
				lastIsDead = flag;
				lastKeyState = (byte[])nativeState.Clone();
			}
		}

		private static void ClearKeyboardBuffer(int vk, int sc, IntPtr hkl)
		{
			StringBuilder stringBuilder = new StringBuilder(10);
			int num;
			do
			{
				byte[] lpKeyState = new byte[255];
				num = ToUnicodeEx(vk, sc, lpKeyState, stringBuilder, stringBuilder.Capacity, 0, hkl);
			}
			while (num < 0);
		}

		private static IntPtr GetActiveKeyboard()
		{
			IntPtr foregroundWindow = ThreadNativeMethods.GetForegroundWindow();
			int processId;
			int windowThreadProcessId = ThreadNativeMethods.GetWindowThreadProcessId(foregroundWindow, out processId);
			return GetKeyboardLayout(windowThreadProcessId);
		}

		[DllImport("user32.dll")]
		[Obsolete("Use ToUnicodeEx instead")]
		public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);

		[DllImport("user32.dll")]
		public static extern int ToUnicodeEx(int wVirtKey, int wScanCode, byte[] lpKeyState, [Out][MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff, int cchBuff, int wFlags, IntPtr dwhkl);

		[DllImport("user32.dll")]
		public static extern int GetKeyboardState(byte[] pbKeyState);

		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
		public static extern short GetKeyState(int vKey);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		internal static extern int MapVirtualKeyEx(int uCode, int uMapType, IntPtr dwhkl);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		internal static extern IntPtr GetKeyboardLayout(int dwLayout);
	}
	internal static class Messages
	{
		public const int WM_MOUSEMOVE = 512;

		public const int WM_LBUTTONDOWN = 513;

		public const int WM_RBUTTONDOWN = 516;

		public const int WM_MBUTTONDOWN = 519;

		public const int WM_LBUTTONUP = 514;

		public const int WM_RBUTTONUP = 517;

		public const int WM_MBUTTONUP = 520;

		public const int WM_LBUTTONDBLCLK = 515;

		public const int WM_RBUTTONDBLCLK = 518;

		public const int WM_MBUTTONDBLCLK = 521;

		public const int WM_MOUSEWHEEL = 522;

		public const int WM_XBUTTONDOWN = 523;

		public const int WM_XBUTTONUP = 524;

		public const int WM_XBUTTONDBLCLK = 525;

		public const int WM_MOUSEHWHEEL = 526;

		public const int WM_KEYDOWN = 256;

		public const int WM_KEYUP = 257;

		public const int WM_SYSKEYDOWN = 260;

		public const int WM_SYSKEYUP = 261;
	}
	internal static class ThreadNativeMethods
	{
		[DllImport("kernel32")]
		internal static extern int GetCurrentThreadId();

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		internal static extern IntPtr GetForegroundWindow();

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		internal static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
	}
}
namespace Gma.System.MouseKeyHook.Implementation
{
	internal class Chord : IEnumerable<Keys>, IEnumerable
	{
		private readonly Keys[] _keys;

		public int Count => _keys.Length;

		internal Chord(IEnumerable<Keys> additionalKeys)
		{
			_keys = (from k in additionalKeys
				select k.Normalize() into k
				orderby k
				select k).ToArray();
		}

		public IEnumerator<Keys> GetEnumerator()
		{
			return _keys.Cast<Keys>().GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public override string ToString()
		{
			return string.Join("+", _keys);
		}

		public static Chord FromString(string chord)
		{
			IEnumerable<Keys> collection = (from p in chord.Split(new char[1] { '+' })
				select Enum.Parse(typeof(Keys), p)).Cast<Keys>();
			Stack<Keys> additionalKeys = new Stack<Keys>(collection);
			return new Chord(additionalKeys);
		}

		protected bool Equals(Chord other)
		{
			if (_keys.Length != other._keys.Length)
			{
				return false;
			}
			return Enumerable.SequenceEqual(_keys, other._keys);
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			if (this == obj)
			{
				return true;
			}
			if (obj.GetType() != GetType())
			{
				return false;
			}
			return Equals((Chord)obj);
		}

		public override int GetHashCode()
		{
			return (_keys.Length + 13) ^ (int)(((_keys.Length != 0) ? ((uint)_keys[0] ^ (uint)_keys[_keys.Length - 1]) : 0) * 397);
		}
	}
	internal class AppKeyListener : KeyListener
	{
		public AppKeyListener()
			: base(HookHelper.HookAppKeyboard)
		{
		}

		protected override IEnumerable<KeyPressEventArgsExt> GetPressEventArgs(CallbackData data)
		{
			return KeyPressEventArgsExt.FromRawDataApp(data);
		}

		protected override KeyEventArgsExt GetDownUpEventArgs(CallbackData data)
		{
			return KeyEventArgsExt.FromRawDataApp(data);
		}
	}
	internal class AppMouseListener : MouseListener
	{
		public AppMouseListener()
			: base(HookHelper.HookAppMouse)
		{
		}

		protected override MouseEventExtArgs GetEventArgs(CallbackData data)
		{
			return MouseEventExtArgs.FromRawDataApp(data);
		}
	}
	internal class ButtonSet
	{
		private MouseButtons m_Set;

		public ButtonSet()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			m_Set = (MouseButtons)0;
		}

		public void Add(MouseButtons element)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			m_Set |= element;
		}

		public void Remove(MouseButtons element)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			m_Set &= ~element;
		}

		public bool Contains(MouseButtons element)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			return (m_Set & element) > 0;
		}
	}
	internal static class KeysExtensions
	{
		public static Keys Normalize(this Keys key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((key & 0xA2) == 162 || (key & 0xA3) == 163)
			{
				return (Keys)131072;
			}
			if ((key & 0xA0) == 160 || (key & 0xA1) == 161)
			{
				return (Keys)65536;
			}
			if ((key & 0xA4) == 164 || (key & 0xA5) == 165)
			{
				return (Keys)262144;
			}
			return key;
		}
	}
	internal abstract class BaseListener : IDisposable
	{
		protected HookResult Handle { get; set; }

		protected BaseListener(Subscribe subscribe)
		{
			Handle = subscribe(Callback);
		}

		public void Dispose()
		{
			Handle.Dispose();
		}

		protected abstract bool Callback(CallbackData data);
	}
	internal delegate bool Callback(CallbackData data);
	internal class GlobalKeyListener : KeyListener
	{
		public GlobalKeyListener()
			: base(HookHelper.HookGlobalKeyboard)
		{
		}

		protected override IEnumerable<KeyPressEventArgsExt> GetPressEventArgs(CallbackData data)
		{
			return KeyPressEventArgsExt.FromRawDataGlobal(data);
		}

		protected override KeyEventArgsExt GetDownUpEventArgs(CallbackData data)
		{
			return KeyEventArgsExt.FromRawDataGlobal(data);
		}
	}
	internal class GlobalMouseListener : MouseListener
	{
		private readonly int m_SystemDoubleClickTime;

		private MouseButtons m_PreviousClicked;

		private Point m_PreviousClickedPosition;

		private int m_PreviousClickedTime;

		public GlobalMouseListener()
			: base(HookHelper.HookGlobalMouse)
		{
			m_SystemDoubleClickTime = MouseNativeMethods.GetDoubleClickTime();
		}

		protected override void ProcessDown(ref MouseEventExtArgs e)
		{
			if (IsDoubleClick(e))
			{
				e = e.ToDoubleClickEventArgs();
			}
			base.ProcessDown(ref e);
		}

		protected override void ProcessUp(ref MouseEventExtArgs e)
		{
			base.ProcessUp(ref e);
			if (((MouseEventArgs)e).Clicks == 2)
			{
				StopDoubleClickWaiting();
			}
			if (((MouseEventArgs)e).Clicks == 1)
			{
				StartDoubleClickWaiting(e);
			}
		}

		private void StartDoubleClickWaiting(MouseEventExtArgs e)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			m_PreviousClicked = ((MouseEventArgs)e).Button;
			m_PreviousClickedTime = e.Timestamp;
			m_PreviousClickedPosition = e.Point;
		}

		private void StopDoubleClickWaiting()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			m_PreviousClicked = (MouseButtons)0;
			m_PreviousClickedTime = 0;
			m_PreviousClickedPosition = new Point(0, 0);
		}

		private bool IsDoubleClick(MouseEventExtArgs e)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return ((MouseEventArgs)e).Button == m_PreviousClicked && e.Point == m_PreviousClickedPosition && e.Timestamp - m_PreviousClickedTime <= m_SystemDoubleClickTime;
		}

		protected override MouseEventExtArgs GetEventArgs(CallbackData data)
		{
			return MouseEventExtArgs.FromRawDataGlobal(data);
		}
	}
	internal class AppEventFacade : EventFacade
	{
		protected override MouseListener CreateMouseListener()
		{
			return new AppMouseListener();
		}

		protected override KeyListener CreateKeyListener()
		{
			return new AppKeyListener();
		}
	}
	internal abstract class EventFacade : IKeyboardMouseEvents, IKeyboardEvents, IMouseEvents, IDisposable
	{
		private KeyListener m_KeyListenerCache;

		private MouseListener m_MouseListenerCache;

		public event KeyEventHandler KeyDown
		{
			add
			{
				GetKeyListener().KeyDown += value;
			}
			remove
			{
				GetKeyListener().KeyDown -= value;
			}
		}

		public event KeyPressEventHandler KeyPress
		{
			add
			{
				GetKeyListener().KeyPress += value;
			}
			remove
			{
				GetKeyListener().KeyPress -= value;
			}
		}

		public event KeyEventHandler KeyUp
		{
			add
			{
				GetKeyListener().KeyUp += value;
			}
			remove
			{
				GetKeyListener().KeyUp -= value;
			}
		}

		public event MouseEventHandler MouseMove
		{
			add
			{
				GetMouseListener().MouseMove += value;
			}
			remove
			{
				GetMouseListener().MouseMove -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseMoveExt
		{
			add
			{
				GetMouseListener().MouseMoveExt += value;
			}
			remove
			{
				GetMouseListener().MouseMoveExt -= value;
			}
		}

		public event MouseEventHandler MouseClick
		{
			add
			{
				GetMouseListener().MouseClick += value;
			}
			remove
			{
				GetMouseListener().MouseClick -= value;
			}
		}

		public event MouseEventHandler MouseDown
		{
			add
			{
				GetMouseListener().MouseDown += value;
			}
			remove
			{
				GetMouseListener().MouseDown -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDownExt
		{
			add
			{
				GetMouseListener().MouseDownExt += value;
			}
			remove
			{
				GetMouseListener().MouseDownExt -= value;
			}
		}

		public event MouseEventHandler MouseUp
		{
			add
			{
				GetMouseListener().MouseUp += value;
			}
			remove
			{
				GetMouseListener().MouseUp -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseUpExt
		{
			add
			{
				GetMouseListener().MouseUpExt += value;
			}
			remove
			{
				GetMouseListener().MouseUpExt -= value;
			}
		}

		public event MouseEventHandler MouseWheel
		{
			add
			{
				GetMouseListener().MouseWheel += value;
			}
			remove
			{
				GetMouseListener().MouseWheel -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseWheelExt
		{
			add
			{
				GetMouseListener().MouseWheelExt += value;
			}
			remove
			{
				GetMouseListener().MouseWheelExt -= value;
			}
		}

		public event MouseEventHandler MouseDoubleClick
		{
			add
			{
				GetMouseListener().MouseDoubleClick += value;
			}
			remove
			{
				GetMouseListener().MouseDoubleClick -= value;
			}
		}

		public event MouseEventHandler MouseDragStarted
		{
			add
			{
				GetMouseListener().MouseDragStarted += value;
			}
			remove
			{
				GetMouseListener().MouseDragStarted -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDragStartedExt
		{
			add
			{
				GetMouseListener().MouseDragStartedExt += value;
			}
			remove
			{
				GetMouseListener().MouseDragStartedExt -= value;
			}
		}

		public event MouseEventHandler MouseDragFinished
		{
			add
			{
				GetMouseListener().MouseDragFinished += value;
			}
			remove
			{
				GetMouseListener().MouseDragFinished -= value;
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDragFinishedExt
		{
			add
			{
				GetMouseListener().MouseDragFinishedExt += value;
			}
			remove
			{
				GetMouseListener().MouseDragFinishedExt -= value;
			}
		}

		public void Dispose()
		{
			if (m_MouseListenerCache != null)
			{
				m_MouseListenerCache.Dispose();
			}
			if (m_KeyListenerCache != null)
			{
				m_KeyListenerCache.Dispose();
			}
		}

		private KeyListener GetKeyListener()
		{
			KeyListener keyListenerCache = m_KeyListenerCache;
			if (keyListenerCache != null)
			{
				return keyListenerCache;
			}
			return m_KeyListenerCache = CreateKeyListener();
		}

		private MouseListener GetMouseListener()
		{
			MouseListener mouseListenerCache = m_MouseListenerCache;
			if (mouseListenerCache != null)
			{
				return mouseListenerCache;
			}
			return m_MouseListenerCache = CreateMouseListener();
		}

		protected abstract MouseListener CreateMouseListener();

		protected abstract KeyListener CreateKeyListener();
	}
	internal class GlobalEventFacade : EventFacade
	{
		protected override MouseListener CreateMouseListener()
		{
			return new GlobalMouseListener();
		}

		protected override KeyListener CreateKeyListener()
		{
			return new GlobalKeyListener();
		}
	}
	public class KeyboardState
	{
		private readonly byte[] m_KeyboardStateNative;

		private KeyboardState(byte[] keyboardStateNative)
		{
			m_KeyboardStateNative = keyboardStateNative;
		}

		public static KeyboardState GetCurrent()
		{
			byte[] array = new byte[256];
			KeyboardNativeMethods.GetKeyboardState(array);
			return new KeyboardState(array);
		}

		internal byte[] GetNativeState()
		{
			return m_KeyboardStateNative;
		}

		public bool IsDown(Keys key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Invalid comparison between Unknown and I4
			if ((int)key < 256)
			{
				return IsDownRaw(key);
			}
			if ((int)key == 262144)
			{
				return IsDownRaw((Keys)164) || IsDownRaw((Keys)165);
			}
			if ((int)key == 65536)
			{
				return IsDownRaw((Keys)160) || IsDownRaw((Keys)161);
			}
			if ((int)key == 131072)
			{
				return IsDownRaw((Keys)162) || IsDownRaw((Keys)163);
			}
			return false;
		}

		private bool IsDownRaw(Keys key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			byte keyState = GetKeyState(key);
			return GetHighBit(keyState);
		}

		public bool IsToggled(Keys key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			byte keyState = GetKeyState(key);
			return GetLowBit(keyState);
		}

		public bool AreAllDown(IEnumerable<Keys> keys)
		{
			return keys.All(IsDown);
		}

		private byte GetKeyState(Keys key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Expected I4, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)key;
			if (num < 0 || num > 255)
			{
				throw new ArgumentOutOfRangeException("key", key, "The value must be between 0 and 255.");
			}
			return m_KeyboardStateNative[num];
		}

		private static bool GetHighBit(byte value)
		{
			return value >> 7 != 0;
		}

		private static bool GetLowBit(byte value)
		{
			return (value & 1) != 0;
		}
	}
	internal delegate HookResult Subscribe(Callback callbck);
	internal static class NativeMethods
	{
		private const int SM_CXDRAG = 68;

		private const int SM_CYDRAG = 69;

		[DllImport("user32.dll")]
		private static extern int GetSystemMetrics(int index);

		public static int GetXDragThreshold()
		{
			return GetSystemMetrics(68);
		}

		public static int GetYDragThreshold()
		{
			return GetSystemMetrics(69);
		}
	}
	internal abstract class MouseListener : BaseListener, IMouseEvents
	{
		private readonly ButtonSet m_DoubleDown;

		private readonly ButtonSet m_SingleDown;

		private readonly Point m_UninitialisedPoint = new Point(-1, -1);

		private readonly int m_xDragThreshold;

		private readonly int m_yDragThreshold;

		private Point m_DragStartPosition;

		private bool m_IsDragging;

		private Point m_PreviousPosition;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseMove;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseClick;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseDown;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseUp;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseWheel;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseDoubleClick;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseDragStarted;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MouseEventHandler m_MouseDragFinished;

		public event MouseEventHandler MouseMove
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseMove;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseMove, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseMove;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseMove, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseMoveExt;

		public event MouseEventHandler MouseClick
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseClick;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseClick, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseClick;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseClick, value2, val2);
				}
				while (val != val2);
			}
		}

		public event MouseEventHandler MouseDown
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDown;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDown, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDown;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDown, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDownExt;

		public event MouseEventHandler MouseUp
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseUp;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseUp, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseUp;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseUp, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseUpExt;

		public event MouseEventHandler MouseWheel
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseWheel;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseWheel, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseWheel;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseWheel, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseWheelExt;

		public event MouseEventHandler MouseDoubleClick
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDoubleClick;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDoubleClick, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDoubleClick;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDoubleClick, value2, val2);
				}
				while (val != val2);
			}
		}

		public event MouseEventHandler MouseDragStarted
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDragStarted;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDragStarted, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDragStarted;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDragStarted, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDragStartedExt;

		public event MouseEventHandler MouseDragFinished
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDragFinished;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDragFinished, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				MouseEventHandler val = this.m_MouseDragFinished;
				MouseEventHandler val2;
				do
				{
					val2 = val;
					MouseEventHandler value2 = (MouseEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_MouseDragFinished, value2, val2);
				}
				while (val != val2);
			}
		}

		public event EventHandler<MouseEventExtArgs> MouseDragFinishedExt;

		protected MouseListener(Subscribe subscribe)
			: base(subscribe)
		{
			m_xDragThreshold = NativeMethods.GetXDragThreshold();
			m_yDragThreshold = NativeMethods.GetYDragThreshold();
			m_IsDragging = false;
			m_PreviousPosition = m_UninitialisedPoint;
			m_DragStartPosition = m_UninitialisedPoint;
			m_DoubleDown = new ButtonSet();
			m_SingleDown = new ButtonSet();
		}

		protected override bool Callback(CallbackData data)
		{
			MouseEventExtArgs e = GetEventArgs(data);
			if (e.IsMouseButtonDown)
			{
				ProcessDown(ref e);
			}
			if (e.IsMouseButtonUp)
			{
				ProcessUp(ref e);
			}
			if (e.WheelScrolled)
			{
				ProcessWheel(ref e);
			}
			if (HasMoved(e.Point))
			{
				ProcessMove(ref e);
			}
			ProcessDrag(ref e);
			return !e.Handled;
		}

		protected abstract MouseEventExtArgs GetEventArgs(CallbackData data);

		protected virtual void ProcessWheel(ref MouseEventExtArgs e)
		{
			OnWheel((MouseEventArgs)(object)e);
			OnWheelExt(e);
		}

		protected virtual void ProcessDown(ref MouseEventExtArgs e)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			OnDown((MouseEventArgs)(object)e);
			OnDownExt(e);
			if (!e.Handled)
			{
				if (((MouseEventArgs)e).Clicks == 2)
				{
					m_DoubleDown.Add(((MouseEventArgs)e).Button);
				}
				if (((MouseEventArgs)e).Clicks == 1)
				{
					m_SingleDown.Add(((MouseEventArgs)e).Button);
				}
			}
		}

		protected virtual void ProcessUp(ref MouseEventExtArgs e)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			OnUp((MouseEventArgs)(object)e);
			OnUpExt(e);
			if (!e.Handled)
			{
				if (m_SingleDown.Contains(((MouseEventArgs)e).Button))
				{
					OnClick((MouseEventArgs)(object)e);
					m_SingleDown.Remove(((MouseEventArgs)e).Button);
				}
				if (m_DoubleDown.Contains(((MouseEventArgs)e).Button))
				{
					e = e.ToDoubleClickEventArgs();
					OnDoubleClick((MouseEventArgs)(object)e);
					m_DoubleDown.Remove(((MouseEventArgs)e).Button);
				}
			}
		}

		private void ProcessMove(ref MouseEventExtArgs e)
		{
			m_PreviousPosition = e.Point;
			OnMove((MouseEventArgs)(object)e);
			OnMoveExt(e);
		}

		private void ProcessDrag(ref MouseEventExtArgs e)
		{
			if (m_SingleDown.Contains((MouseButtons)1048576))
			{
				if (m_DragStartPosition.Equals(m_UninitialisedPoint))
				{
					m_DragStartPosition = e.Point;
				}
				ProcessDragStarted(ref e);
			}
			else
			{
				m_DragStartPosition = m_UninitialisedPoint;
				ProcessDragFinished(ref e);
			}
		}

		private void ProcessDragStarted(ref MouseEventExtArgs e)
		{
			if (!m_IsDragging)
			{
				bool flag = Math.Abs(e.Point.X - m_DragStartPosition.X) > m_xDragThreshold;
				bool flag2 = Math.Abs(e.Point.Y - m_DragStartPosition.Y) > m_yDragThreshold;
				m_IsDragging = flag || flag2;
				if (m_IsDragging)
				{
					OnDragStarted((MouseEventArgs)(object)e);
					OnDragStartedExt(e);
				}
			}
		}

		private void ProcessDragFinished(ref MouseEventExtArgs e)
		{
			if (m_IsDragging)
			{
				OnDragFinished((MouseEventArgs)(object)e);
				OnDragFinishedExt(e);
				m_IsDragging = false;
			}
		}

		private bool HasMoved(Point actualPoint)
		{
			return m_PreviousPosition != actualPoint;
		}

		protected virtual void OnMove(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseMove;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnMoveExt(MouseEventExtArgs e)
		{
			this.MouseMoveExt?.Invoke(this, e);
		}

		protected virtual void OnClick(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseClick;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnDown(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseDown;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnDownExt(MouseEventExtArgs e)
		{
			this.MouseDownExt?.Invoke(this, e);
		}

		protected virtual void OnUp(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseUp;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnUpExt(MouseEventExtArgs e)
		{
			this.MouseUpExt?.Invoke(this, e);
		}

		protected virtual void OnWheel(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseWheel;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnWheelExt(MouseEventExtArgs e)
		{
			this.MouseWheelExt?.Invoke(this, e);
		}

		protected virtual void OnDoubleClick(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseDoubleClick;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnDragStarted(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseDragStarted;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnDragStartedExt(MouseEventExtArgs e)
		{
			this.MouseDragStartedExt?.Invoke(this, e);
		}

		protected virtual void OnDragFinished(MouseEventArgs e)
		{
			MouseEventHandler val = this.MouseDragFinished;
			if (val != null)
			{
				val.Invoke((object)this, e);
			}
		}

		protected virtual void OnDragFinishedExt(MouseEventExtArgs e)
		{
			this.MouseDragFinishedExt?.Invoke(this, e);
		}
	}
	internal abstract class KeyListener : BaseListener, IKeyboardEvents
	{
		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private KeyEventHandler m_KeyDown;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private KeyPressEventHandler m_KeyPress;

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private KeyEventHandler m_KeyUp;

		public event KeyEventHandler KeyDown
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyEventHandler val = this.m_KeyDown;
				KeyEventHandler val2;
				do
				{
					val2 = val;
					KeyEventHandler value2 = (KeyEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyDown, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyEventHandler val = this.m_KeyDown;
				KeyEventHandler val2;
				do
				{
					val2 = val;
					KeyEventHandler value2 = (KeyEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyDown, value2, val2);
				}
				while (val != val2);
			}
		}

		public event KeyPressEventHandler KeyPress
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyPressEventHandler val = this.m_KeyPress;
				KeyPressEventHandler val2;
				do
				{
					val2 = val;
					KeyPressEventHandler value2 = (KeyPressEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyPress, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyPressEventHandler val = this.m_KeyPress;
				KeyPressEventHandler val2;
				do
				{
					val2 = val;
					KeyPressEventHandler value2 = (KeyPressEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyPress, value2, val2);
				}
				while (val != val2);
			}
		}

		public event KeyEventHandler KeyUp
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyEventHandler val = this.m_KeyUp;
				KeyEventHandler val2;
				do
				{
					val2 = val;
					KeyEventHandler value2 = (KeyEventHandler)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyUp, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				KeyEventHandler val = this.m_KeyUp;
				KeyEventHandler val2;
				do
				{
					val2 = val;
					KeyEventHandler value2 = (KeyEventHandler)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_KeyUp, value2, val2);
				}
				while (val != val2);
			}
		}

		protected KeyListener(Subscribe subscribe)
			: base(subscribe)
		{
		}

		public void InvokeKeyDown(KeyEventArgsExt e)
		{
			KeyEventHandler val = this.KeyDown;
			if (val != null && !((KeyEventArgs)e).Handled && e.IsKeyDown)
			{
				val.Invoke((object)this, (KeyEventArgs)(object)e);
			}
		}

		public void InvokeKeyPress(KeyPressEventArgsExt e)
		{
			KeyPressEventHandler val = this.KeyPress;
			if (val != null && !((KeyPressEventArgs)e).Handled && !e.IsNonChar)
			{
				val.Invoke((object)this, (KeyPressEventArgs)(object)e);
			}
		}

		public void InvokeKeyUp(KeyEventArgsExt e)
		{
			KeyEventHandler val = this.KeyUp;
			if (val != null && !((KeyEventArgs)e).Handled && e.IsKeyUp)
			{
				val.Invoke((object)this, (KeyEventArgs)(object)e);
			}
		}

		protected override bool Callback(CallbackData data)
		{
			KeyEventArgsExt downUpEventArgs = GetDownUpEventArgs(data);
			InvokeKeyDown(downUpEventArgs);
			if (this.KeyPress != null)
			{
				IEnumerable<KeyPressEventArgsExt> pressEventArgs = GetPressEventArgs(data);
				foreach (KeyPressEventArgsExt item in pressEventArgs)
				{
					InvokeKeyPress(item);
				}
			}
			InvokeKeyUp(downUpEventArgs);
			return !((KeyEventArgs)downUpEventArgs).Handled;
		}

		protected abstract IEnumerable<KeyPressEventArgsExt> GetPressEventArgs(CallbackData data);

		protected abstract KeyEventArgsExt GetDownUpEventArgs(CallbackData data);
	}
}
