-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomGlobalHotkeysExt.cs
76 lines (65 loc) · 2.68 KB
/
CustomGlobalHotkeysExt.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Windows.Forms;
using System.Collections.Generic;
using KeePass.Plugins;
using KeePass.Util;
namespace CustomGlobalHotkeys
{
public class KeyBinding
{
public bool enabled;
public Keys key;
public string sequence;
public int id = -1000;
}
public sealed class CustomGlobalHotkeysExt : Plugin
{
private IPluginHost m_host = null;
private string MySequence;
private List<KeyBinding> KeyBindings = new List<KeyBinding>();
public override bool Initialize(IPluginHost host)
{
m_host = host;
MySequence = "";
LoadBindings();
HotKeyInternals.HotKeyPressed += HotKeyPressed;
AutoType.FilterCompilePre += FilterCompilePre;
foreach (KeyBinding binding in KeyBindings) binding.id = HotKeyInternals.InternalRegisterHotKey(binding.key);
return true;
}
public override void Terminate()
{
foreach (KeyBinding binding in KeyBindings) HotKeyInternals.InternalUnregisterHotKey(binding.id);
HotKeyInternals.HotKeyPressed -= HotKeyPressed;
AutoType.FilterCompilePre -= FilterCompilePre;
}
private void FilterCompilePre(object sender, AutoTypeEventArgs e)
{
if (MySequence != "") e.Sequence = MySequence;
MySequence = "";
}
private void HotKeyPressed(object sender, HotKeyEventArgs e)
{
Keys key = e.Key;
if (0 != (e.Modifiers & KeyModifiers.Alt)) key |= Keys.Alt;
if (0 != (e.Modifiers & KeyModifiers.Control)) key |= Keys.Control;
if (0 != (e.Modifiers & KeyModifiers.Shift)) key |= Keys.Shift;
foreach (KeyBinding binding in KeyBindings)
{
if (binding.enabled && (binding.key == key))
{
MySequence = binding.sequence;
break;
}
}
m_host.MainWindow.ExecuteGlobalAutoType();
MySequence = "";
}
private void LoadBindings()
{
KeyBindings.Add(new KeyBinding { enabled = true, key = Keys.Control | Keys.Alt | Keys.S, sequence = "{Password}{ENTER}" });
KeyBindings.Add(new KeyBinding { enabled = true, key = Keys.Control | Keys.Alt | Keys.Y, sequence = "{TOTP}{ENTER}" });
KeyBindings.Add(new KeyBinding { enabled = true, key = Keys.Control | Keys.Alt | Keys.P, sequence = "{TCATO:false}{CLEARFIELD}{S:password reset url}{ENTER}" });
KeyBindings.Add(new KeyBinding { enabled = true, key = Keys.Control | Keys.Alt | Keys.I, sequence = "{PICKFIELD}" });
}
}
}