Skip to content

Commit fac89fe

Browse files
committed
New option: Auto-Type username only
Closes #11
1 parent e1c0700 commit fac89fe

File tree

9 files changed

+126
-14
lines changed

9 files changed

+126
-14
lines changed

Translations/AlternateAutoType.de.language.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Increment the TranslationVersion every time the translation file is updated
55
Also update the version.info file
66
-->
7-
<TranslationVersion>6</TranslationVersion>
7+
<TranslationVersion>7</TranslationVersion>
88
<item>
99
<key>ErrorHotKeyAAT</key>
1010
<value>{0} konnte nicht als Hotkey für Alternate Auto-Type registriert werden</value>
@@ -13,6 +13,10 @@
1313
<key>ErrorHotKeyPWOnly</key>
1414
<value>{0} konnte nicht als Hotkey zur Passworteingabe registriert werden</value>
1515
</item>
16+
<item>
17+
<key>ErrorHotKeyUsernameOnly</key>
18+
<value>{0} konnte nicht als Hotkey zur Benutzereingabe registriert werden</value>
19+
</item>
1620
<item>
1721
<key>Options</key>
1822
<value>Alternate Auto-Type Konfiguration</value>
@@ -33,6 +37,10 @@
3337
<key>PasswordEnterHotKey</key>
3438
<value>Passwort + Enter</value>
3539
</item>
40+
<item>
41+
<key>UsernameEnterHotKey</key>
42+
<value>Benutzername + Enter</value>
43+
</item>
3644
<item>
3745
<key>Hotkeys</key>
3846
<value>Hotkeys</value>

Translations/AlternateAutoType.template.language.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<key>ErrorHotKeyPWOnly</key>
1414
<value>{0} could not be registered as password only hotkey</value>
1515
</item>
16+
<item>
17+
<key>ErrorHotKeyUsernameOnly</key>
18+
<value>{0} could not be registered as username only hotkey</value>
19+
</item>
1620
<item>
1721
<key>Options</key>
1822
<value>Alternate Auto-Type configuration</value>
@@ -33,6 +37,10 @@
3337
<key>PasswordEnterHotKey</key>
3438
<value>Password + Enter</value>
3539
</item>
40+
<item>
41+
<key>UsernameEnterHotKey</key>
42+
<value>Username + Enter</value>
43+
</item>
3644
<item>
3745
<key>Hotkeys</key>
3846
<value>Hotkeys</value>

src/AlternateAutoType.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ private bool PWOnlyHotkeyPressed
4040
{
4141
get { return (m_bKPAutoTypePasswordHotkey || (m_sequence != 0) && (m_sequence == Config.PWOnlyHotkeyID)); }
4242
}
43+
44+
private bool UsernameOnlyHotkeyPressed
45+
{
46+
get { return (m_sequence != 0) && (m_sequence == Config.UsernameOnlyHotkeyID); }
47+
}
4348
#endregion
4449

4550
public override bool Initialize(IPluginHost host)
@@ -112,13 +117,16 @@ private string AdjustSequence(string sequence, bool bResetPWOnly)
112117
{
113118
/*
114119
* Option 1: Hotkey for password only is used => return {PASSWORD}
115-
* Option 2: No placeholder => nothing to do
116-
* Option 3: Placeholder and hotkey for AAT is used => return sequence part AFTER placeholder
117-
* Option 4: Placeholder and hotkey for AAT is not used => return sequence part BEFORE placeholder
120+
* Option 2: Hotkey for username only is used => return {USERNAME}
121+
* Option 3: No placeholder => nothing to do
122+
* Option 4: Placeholder and hotkey for AAT is used => return sequence part AFTER placeholder
123+
* Option 5: Placeholder and hotkey for AAT is not used => return sequence part BEFORE placeholder
118124
*/
119125
bool bPWOnly = PWOnlyHotkeyPressed;
120126
if (bResetPWOnly) CheckKPAutoTypePasswordHotkey(false);
121-
if (bPWOnly && Config.PWEnter) return sequence + "{ENTER}";
127+
if (bPWOnly) return "{PASSWORD}" + (Config.PWEnter ? "{ENTER}" : string.Empty);
128+
if (UsernameOnlyHotkeyPressed) return "{USERNAME}" + (Config.UsernameOnlyEnter ? "{ENTER}" : string.Empty);
129+
122130
int pos = sequence.IndexOf(Config.Placeholder);
123131
if (pos < 0) return sequence;
124132
if (AATHotkeyPressed)
@@ -149,6 +157,7 @@ private void HotKeyPressed(object sender, HotKeyEventArgs e)
149157
lMsg.Add("Hotkey id: " + m_sequence.ToString());
150158
lMsg.Add("PW only hotkey: " + Config.PWOnlyHotkeyID.ToString() + " - " + (Config.PWOnlyHotkeyID == e.ID).ToString());
151159
lMsg.Add("AAT only hotkey: " + Config.AATHotkeyID + " - " + (Config.AATHotkeyID == e.ID).ToString());
160+
lMsg.Add("Username only hotkey: " + Config.UsernameOnlyHotkeyID+ " - " + (Config.UsernameOnlyHotkeyID == e.ID).ToString());
152161
PluginDebug.AddInfo("Alternate Auto-Type hotkey detected", 0, lMsg.ToArray());
153162
m_host.MainWindow.ExecuteGlobalAutoType();
154163
m_sequence = 0;
@@ -170,6 +179,12 @@ private void HotkeysActivate()
170179
if (Config.PWOnlyHotkeyID == 0)
171180
Tools.ShowError(string.Format(PluginTranslate.ErrorHotKeyPWOnly, Config.PWOnlyHotkey.ToString()));
172181
}
182+
if (Config.UsernameOnlyHotkey != Keys.None)
183+
{
184+
Config.UsernameOnlyHotkeyID = PTHotKeyManager.RegisterHotKey(Config.UsernameOnlyHotkey);
185+
if (Config.UsernameOnlyHotkeyID == 0)
186+
Tools.ShowError(string.Format(PluginTranslate.ErrorHotKeyUsernameOnly, Config.UsernameOnlyHotkey.ToString()));
187+
}
173188
}
174189

175190
private void HotkeysDeactivate()
@@ -179,6 +194,8 @@ private void HotkeysDeactivate()
179194
PTHotKeyManager.UnregisterHotKey(Config.AATHotkeyID);
180195
if ((Config.PWOnlyHotkey != Keys.None) && !Config.KPAutoTypePWPossible)
181196
PTHotKeyManager.UnregisterHotKey(Config.PWOnlyHotkeyID);
197+
if (Config.UsernameOnlyHotkey != Keys.None)
198+
PTHotKeyManager.UnregisterHotKey(Config.UsernameOnlyHotkeyID);
182199
}
183200
#endregion
184201

@@ -657,6 +674,8 @@ private void OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
657674
Options options = new Options();
658675
options.AATHotkey = Config.AATHotkey;
659676
options.PWOnlyHotkey = Config.PWOnlyHotkey;
677+
options.UsernameOnlyHotkey = Config.UsernameOnlyHotkey;
678+
options.UsernameOnlyEnter = Config.UsernameOnlyEnter;
660679
options.cbPWHotkey.SelectedIndex = Config.PWEnter ? 1 : 0;
661680
options.cbColumnsSortable.Checked = Config.ColumnsSortable;
662681
options.cbColumnsRememberSort.Checked = Config.ColumnsRememberSorting;
@@ -685,6 +704,8 @@ private void OptionsForm_Closed(object sender, Tools.OptionsFormsEventArgs e)
685704
HotkeysDeactivate();
686705
Config.AATHotkey = options.AATHotkey;
687706
Config.PWOnlyHotkey = options.PWOnlyHotkey;
707+
Config.UsernameOnlyHotkey = options.UsernameOnlyHotkey;
708+
Config.UsernameOnlyEnter = options.UsernameOnlyEnter;
688709
Config.ColumnsSortable = options.cbColumnsSortable.Checked;
689710
Config.ColumnsRememberSorting = options.cbColumnsRememberSort.Checked;
690711
Config.AddDBColumn = options.cbDBColumn.Checked;
@@ -694,7 +715,7 @@ private void OptionsForm_Closed(object sender, Tools.OptionsFormsEventArgs e)
694715
Config.ExcludeExpiredGroups = options.cbExcludeExpiredGroups.Checked;
695716
Config.SearchAsYouType = options.cbSearchAsYouType.Checked;
696717

697-
if ((Config.AATHotkey != Keys.None) || (Config.PWOnlyHotkey != Keys.None))
718+
if ((Config.AATHotkey != Keys.None) || (Config.PWOnlyHotkey != Keys.None) || (Config.UsernameOnlyHotkey != Keys.None))
698719
HotkeysActivate();
699720
}
700721
#endregion

src/Config.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,33 @@ public static bool PWEnter
118118
get { return Program.Config.CustomConfig.GetBool(m_PWEnterConfig, false); }
119119
set { Program.Config.CustomConfig.SetBool(m_PWEnterConfig, value); }
120120
}
121+
122+
public static Keys UsernameOnlyHotkey
123+
{
124+
get { return ReadKey(m_UserOnlyHotkeyConfig, PluginTranslate.ErrorHotKeyUsernameOnly); }
125+
set { SetKey(m_UserOnlyHotkeyConfig, value); }
126+
}
127+
public static int UsernameOnlyHotkeyID = 0;
128+
public static bool UsernameOnlyEnter
129+
{
130+
get { return Program.Config.CustomConfig.GetBool(m_UserOnlyEnterConfig, false); }
131+
set { Program.Config.CustomConfig.SetBool(m_UserOnlyEnterConfig, value); }
132+
}
133+
121134
public static Keys AATHotkey
122135
{
123136
get { return ReadKey(m_AATHotkeyConfig, PluginTranslate.ErrorHotKeyAAT); }
124137
set { SetKey(m_AATHotkeyConfig, value); }
125138
}
126139
public static int AATHotkeyID = 0;
140+
127141
public static Keys PWOnlyHotkey
128142
{
129143
get { return ReadKey(m_PWOnlyHotkeyConfig, PluginTranslate.ErrorHotKeyPWOnly); }
130144
set { SetKey(m_PWOnlyHotkeyConfig, value); }
131145
}
132146
public static int PWOnlyHotkeyID = 0;
147+
133148
public static bool ExcludeExpiredGroups
134149
{
135150
get { return Program.Config.CustomConfig.GetBool(m_ExcludeExpiredGroups, true); }
@@ -139,6 +154,8 @@ public static bool ExcludeExpiredGroups
139154
private static string m_AATHotkeyConfig = "AlternateAutoType.AATHotkey";
140155
private static string m_PWOnlyHotkeyConfig = "AlternateAutoType.PWOnlyHotkey";
141156
private static string m_PWEnterConfig = "AlternateAutoType.PWEnter";
157+
private static string m_UserOnlyHotkeyConfig = "AlternateAutoType.UserOnlyHotkey";
158+
private static string m_UserOnlyEnterConfig = "AlternateAutoType.UserOnlyEnter";
142159
private static string m_SearchAsYouType = "AlternateAutoType.SearchAsYouType";
143160
private static string m_AddDBColumnConfig = "AlternateAutoType.AddDBColumn";
144161
private static string m_ColumnsSortableConfig = "AlternateAutoType.ColumnsSortable";

src/Options.Designer.cs

Lines changed: 43 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public Options()
2020
lGAT.Text = PluginTranslate.GlobalAutotypeHotKey;
2121
lAAT.Text = PluginTranslate.AATHotKey;
2222
cbPWEnter.Text = PluginTranslate.PasswordEnterHotKey;
23+
cbUsernameEnter.Text = PluginTranslate.UsernameEnterHotKey;
2324
cbPWHotkey.Items.Clear();
2425
cbPWHotkey.Items.Add(PluginTranslate.PasswordOnlyHotKey);
2526
cbPWHotkey.Items.Add(PluginTranslate.PasswordEnterHotKey);
@@ -63,6 +64,18 @@ public Keys PWOnlyHotkey
6364
set { SetHotKey(tbPWOnly, value); }
6465
}
6566

67+
public Keys UsernameOnlyHotkey
68+
{
69+
get { return GetHotKey(tbUsernameOnly); }
70+
set { SetHotKey(tbUsernameOnly, value); }
71+
}
72+
73+
public bool UsernameOnlyEnter
74+
{
75+
get { return cbUsernameEnter.Checked; }
76+
set { cbUsernameEnter.Checked = value; }
77+
}
78+
6679
private void SetHotKey(HotKeyControlEx hkBox, Keys hk)
6780
{
6881
hkBox.HotKey = hk;
@@ -103,12 +116,15 @@ internal void OptionsForm_Shown(object sender, EventArgs e)
103116
cbPWHotkey.Visible = cbPWHotkey.TabStop = !Config.KPAutoTypePWPossible;
104117
cbPWEnter.Checked = Config.PWEnter;
105118
cbPWEnter.Left = tbPWOnly.Left;
119+
cbUsernameEnter.Left = cbPWEnter.Left;
106120
if (!Config.KPAutoTypePWPossible) return;
107121
Control c = Tools.GetControl("m_lblAutotype", sender as Form);
108122
if (c != null) lGAT.Text = c.Text;
109123
c = Tools.GetControl("m_lblAutotypePassword", sender as Form);
110124
if (c != null) lGATP.Text = c.Text;
111-
TabPage tpPluginOptions = Parent.Parent.Parent as TabPage; //TabPage AlternateAutoType - TabControl - TabPage Plugin Options
125+
else lGATP.Text = KeePass.Resources.KPRes.Password + ":";
126+
lGATU.Text = KeePass.Resources.KPRes.UserName + ":";
127+
TabPage tpPluginOptions = Parent.Parent.Parent as TabPage; //TabPage AlternateAutoType - TabControl - TabPage Plugin Options
112128
if (tpPluginOptions != null) tpPluginOptions.Enter += PluginOptionsEnter;
113129
}
114130

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ KeePass types EITHER everything before OR everything after {AAT}.
2727
//
2828
// You can specify all the values or you can use the default the Revision and
2929
// Build Numbers by using the '*' as shown below:
30-
[assembly: AssemblyVersion("1.18.1")]
31-
[assembly: AssemblyFileVersion("1.18.1")]
30+
[assembly: AssemblyVersion("1.19")]
31+
[assembly: AssemblyFileVersion("1.19")]
3232
[assembly: Guid("78C152F3-EAF8-4FFC-9BE3-F5DC0CD66E5D")]
3333

src/Utilities/PluginTranslation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public static class PluginTranslate
3535
public const string PluginName = "Alternate Auto-Type";
3636
public static readonly string ErrorHotKeyAAT = @"{0} could not be registered as alternate auto-type hotkey";
3737
public static readonly string ErrorHotKeyPWOnly = @"{0} could not be registered as password only hotkey";
38+
public static readonly string ErrorHotKeyUsernameOnly = @"{0} could not be registered as username only hotkey";
3839
public static readonly string Options = @"Alternate Auto-Type configuration";
3940
public static readonly string GlobalAutotypeHotKey = @"Global Auto-Type Hotkey:";
4041
public static readonly string PasswordOnlyHotKey = @"Password Only";
4142
public static readonly string AATHotKey = @"Alternate Auto-Type Hotkey:";
4243
public static readonly string PasswordEnterHotKey = @"Password + Enter";
44+
public static readonly string UsernameEnterHotKey = @"Username + Enter";
4345
public static readonly string Hotkeys = @"Hotkeys";
4446
public static readonly string Integration = @"Auto-Type Entry Selection form enhancements";
4547
public static readonly string ColumnsSortable = @"Click column headers to sort entries";

version.info

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:
2-
AlternateAutoType:1.18.1
3-
AlternateAutoType!de:5
2+
AlternateAutoType:1.19
3+
AlternateAutoType!de:7
44
AlternateAutoType!pt:2
55
AlternateAutoType!ru:4
66
AlternateAutoType!zh:1

0 commit comments

Comments
 (0)