-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathHotKeyMainWindows.cs
53 lines (48 loc) · 1.38 KB
/
HotKeyMainWindows.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using ToDoLib;
namespace Client
{
class HotKeyMainWindows: IDisposable
{
private Window _window;
private HotKey _hotkey;
public HotKeyMainWindows(Window window, ModifierKeys modifierKeys, Keys key)
{
try
{
_window = window;
_hotkey = new HotKey(modifierKeys, key, _window);
_hotkey.HotKeyPressed += KeyPressed;
_window.Closed += (sender, args) => { Dispose(); };
}
catch (Exception ex)
{
var msg = "Error Global HotKey Registered";
Log.Error(msg, ex);
System.Windows.MessageBox.Show(ex.Message, msg, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void KeyPressed(HotKey k)
{
if (_window.WindowState == WindowState.Minimized)
{
_window.Show();
_window.Activate();
_window.WindowState = WindowState.Normal;
}
else
{
_window.WindowState = WindowState.Minimized;
_window.Hide();
}
}
public void Dispose()
{
_hotkey.Dispose();
_hotkey = null;
}
}
}