public void Register_hotkey_and_then_unregister_it_check_that_hotkey_do_not_exists_anmymore() { var winApi = Substitute.For <IWinApi>(); winApi.RegisterHotKey(IntPtr.Zero, 0, Key.A, ModifierKeys.Alt).ReturnsForAnyArgs(true); var manager = new HotKeyManager(winApi); var hotKey = new HotKey(Key.T, ModifierKeys.Shift); var label = "test"; manager.Register(label, hotKey); var resultHotKey = manager.GetHotkey(label); var resultLabel = manager.GetLabel(hotKey); Assert.That(resultHotKey, Is.EqualTo(hotKey)); Assert.That(resultLabel, Is.EqualTo(label)); manager.Unregister(label); resultHotKey = manager.GetHotkey(label); resultLabel = manager.GetLabel(hotKey); Assert.That(resultHotKey, Is.Null); Assert.That(resultLabel, Is.Null.Or.Empty); }
private void saveCommandExecute() { var hotKey = _hotKeyManager.GetHotkey("toggle"); var data = new AppSaveData(_smileCollection.Items) { Key = hotKey.Return(i => i.Key, Key.N), ModsKeys = hotKey.Return(h => h.Modifiers, ModifierKeys.Windows) }; MainAppSaveLoader.Save(data); }
public void Register_hotkey_and_check_that_api_called_and_manager_can_give_correct_data_back() { var apiCalled = false; var winApi = Substitute.For <IWinApi>(); winApi.WhenForAnyArgs(x => x.RegisterHotKey(IntPtr.Zero, 0, Key.A, ModifierKeys.Alt)).Do(info => { apiCalled = true; }); winApi.RegisterHotKey(IntPtr.Zero, 0, Key.A, ModifierKeys.Alt).ReturnsForAnyArgs(true); var manager = new HotKeyManager(winApi); var hotKey = new HotKey(Key.T, ModifierKeys.Shift); var label = "test"; manager.Register(label, hotKey); var resultHotKey = manager.GetHotkey(label); var resultLabel = manager.GetLabel(hotKey); Assert.That(resultHotKey, Is.EqualTo(hotKey)); Assert.That(resultLabel, Is.EqualTo(label)); Assert.That(apiCalled, Is.True); }
private void unload() { var hotKey = _hotKeyManager.GetHotkey("toggle"); var data = new AppSaveData(_smiles.Items) { Key = hotKey.Return(i => i.Key, Key.N), ModsKeys = hotKey.Return(h => h.Modifiers, ModifierKeys.Windows) }; MainAppSaveLoader.Save(data); _hotKeyManager.Unregister("toggle"); }
private void updateHotkeyText() { var hotKey = _hotkeyManager.GetHotkey("toggle"); HotkeyText = hotKey.Return(h => h.ToString(), "No"); }