public GlobalHookBase(List <ShortcutModel> shortcuts) { Shortcuts = shortcuts; KeyboardHook = new KeyboardHookListener(new GlobalHooker()); KeyboardHook.KeyDown += (s, e) => { foreach (var item in Shortcuts) { string keyCode = e.KeyCode.ToString(); if (item.KeyCode == keyCode || $"D{item.KeyCode}" == keyCode) { if (item.AllModifs) { if (e.Modifiers.HasFlag(System.Windows.Forms.Keys.Control) && e.Modifiers.HasFlag(System.Windows.Forms.Keys.Alt)) { item.actionOnClick(); e.Handled = true; } } else { if (item.SelectedModificator == ModificatorNumeration.Ctrl && e.Modifiers == System.Windows.Forms.Keys.Control) //for now ctrl is always first selected modifiers { if (item.actionOnClick != null) { item.actionOnClick(); e.Handled = true; } } else if (item.AlternateSelectedModificator.ToString() == e.Modifiers.ToString()) //alt or shift { if (item.alternateActionOnClick != null) { item.alternateActionOnClick(); e.Handled = true; } } } } } }; KeyboardHook.Start(); }
public MainWindow() { //Check if this is the first application instance. if (Application_Mutex.Mutex() == false) { Environment.Exit(0); //Close this (second) process. } InitializeComponent(); #region Find playback devices (including full names). MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); for (int deviceId = 0; deviceId < WaveOut.DeviceCount; deviceId++) { WaveOutCapabilities capabilities = WaveOut.GetCapabilities(deviceId); foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { if (device.FriendlyName.StartsWith(capabilities.ProductName)) { Available_Devices.Add(new Playback_Device() { ID = deviceId, Name = device.FriendlyName }); } } } #endregion LoadSettings(); Playback_Devices.CollectionChanged += Playback_Devices_CollectionChanged; Playback_Volumes.CollectionChanged += Playback_Volumes_CollectionChanged; Keyboard_Hook.KeyUp += Keyboard_Hook_KeyUp; Keyboard_Hook.KeyDown += Keyboard_Hook_KeyDown; Keyboard_Hook.Start(); //Set the data context for binding. DataContext = this; }