Skip to content

Commit 904064f

Browse files
committed
* Add option to delay Auto-Type in Password Change form
On some *nix systems, KeePass won't fall to background properly after clicking one of the Auto-Type buttons in the Password Change form. To compensate that, it's possible to add an initial delay before starting the Auto-Type. This allows to manually switch to the target window and place the cursor in the proper field. Closes #16
1 parent 631311a commit 904064f

9 files changed

Lines changed: 346 additions & 269 deletions

Translations/PasswordChangeAssistant.de.language.xml

Lines changed: 5 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>9</TranslationVersion>
7+
<TranslationVersion>10</TranslationVersion>
88
<item>
99
<key>OldPW</key>
1010
<value>Altes Passwort:</value>
@@ -129,4 +129,8 @@ Du kannst das jederzeit in den Einstellungen ändern.</value>
129129
<key>ProfileAtLeast1PerSet</key>
130130
<value>Mindestens 1 Zeichen je gewähltem Set *</value>
131131
</item>
132+
<item>
133+
<key>AutotypeDelay</key>
134+
<value>Auto-Type Verzögerung (Sekunden)</value>
135+
</item>
132136
</Translation>

Translations/PasswordChangeAssistant.template.language.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,8 @@ You can change this in the plugin's options anytime.</value>
129129
<key>ProfileAtLeast1PerSet</key>
130130
<value>At least one per set *</value>
131131
</item>
132+
<item>
133+
<key>AutotypeDelay</key>
134+
<value>Auto-Type delay (seconds)</value>
135+
</item>
132136
</Translation>

src/PasswordChangeAssistant.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,32 @@ private void DerefStrings(PCAInitData pcadata, PwEntry pe)
572572

573573
internal static void PasswordType(PwEntry pe, ProtectedString ps)
574574
{
575+
var bAddedDelay = AddDelay();
576+
575577
/* The password string may contain special chars and/or field references
576578
* Easiest way is to set the provided value as new string field
577579
* and have KeePass do the rest
578580
*/
579581
SetPasswordField(pe, ps);
580-
AutoType.PerformIntoPreviousWindow(Program.MainForm, pe,
582+
if (bAddedDelay)
583+
AutoType.PerformIntoCurrentWindow(pe,
581584
Program.MainForm.DocumentManager.SafeFindContainerOf(pe), Config.PCAPluginFieldRef);
585+
else
586+
AutoType.PerformIntoPreviousWindow(Program.MainForm, pe,
587+
Program.MainForm.DocumentManager.SafeFindContainerOf(pe), Config.PCAPluginFieldRef);
582588
SetPasswordField(pe, null);
583589
}
584590

591+
private static bool AddDelay()
592+
{
593+
//https://github.com/Rookiestyle/PasswordChangeAssistant/issues/16
594+
var iDelay = Config.AutotypeDelay;
595+
if (iDelay < 1) return false;
596+
PluginDebug.AddInfo("Adding Auto-Type delay of " + iDelay.ToString() + " seconds");
597+
System.Threading.Thread.Sleep(iDelay * 1000);
598+
return true;
599+
}
600+
585601
internal static void PasswordCopy(PwEntry pe, ProtectedString ps)
586602
{
587603
/* The password string may contain special chars and/or field references
@@ -621,6 +637,7 @@ internal static void PasswordCopy(PwEntry pe, ProtectedString ps)
621637

622638
internal static void SequenceType(PwEntry pe, ProtectedString ps, string sequence)
623639
{
640+
AddDelay();
624641
/* The password string may contain special chars and/or field references
625642
* Easiest way is to set the provided value as new string field
626643
* and have KeePass do the rest
@@ -720,6 +737,7 @@ private void OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
720737
PwProfSyncForm form = new PwProfSyncForm();
721738
form.SetHomeDB(m_host.Database);
722739
form.cbOpenUrlForPwChange.Checked = Config.OpenUrlForPwChange;
740+
form.nupAutotypeDelay.Value = Config.AutotypeDelay;
723741
Tools.AddPluginToOptionsForm(this, form);
724742
}
725743

@@ -735,6 +753,7 @@ private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
735753
bool MoveProfiles = true;
736754
form.GetWorklist(out profilesDB, out profilesOther, out otherDB, out MoveProfiles);
737755
Config.OpenUrlForPwChange = form.cbOpenUrlForPwChange.Checked;
756+
Config.AutotypeDelay = (int)form.nupAutotypeDelay.Value;
738757
form.Dispose();
739758

740759
//Update password profiles in active database

src/PluginTranslation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ Do you want this to be active?
161161
/// At least 1 per set *
162162
/// </summary>
163163
public static readonly string ProfileAtLeast1PerSet = @"At least one per set *";
164+
/// <summary>
165+
/// Auto-Type delay (seconds)
166+
/// </summary>
167+
public static readonly string AutotypeDelay = @"Auto-Type delay (seconds)";
164168
#endregion
165169

166170
#region NO changes in this area

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
//
2525
// You can specify all the values or you can use the default the Revision and
2626
// Build Numbers by using the '*' as shown below:
27-
[assembly: AssemblyVersion("2.14.1")]
28-
[assembly: AssemblyFileVersion("2.14.1")]
27+
[assembly: AssemblyVersion("2.15")]
28+
[assembly: AssemblyFileVersion("2.15")]
2929
[assembly: Guid ("5d5cc62b-d6f6-4e0b-a7ff-3d5ef21dd656")]

0 commit comments

Comments
 (0)