diff --git a/TypeClipboard/Form1.Designer.cs b/TypeClipboard/Form1.Designer.cs index c5d8e0c..772b00a 100644 --- a/TypeClipboard/Form1.Designer.cs +++ b/TypeClipboard/Form1.Designer.cs @@ -28,7 +28,6 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.chkHotkey = new System.Windows.Forms.CheckBox(); @@ -36,7 +35,8 @@ private void InitializeComponent() this.textBox2 = new System.Windows.Forms.TextBox(); this.button3 = new System.Windows.Forms.Button(); this.chkEnter = new System.Windows.Forms.CheckBox(); - this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.tbInterkeyDelay = new System.Windows.Forms.TextBox(); + this.lInterkeyDelay = new System.Windows.Forms.Label(); this.SuspendLayout(); // // textBox1 @@ -66,7 +66,6 @@ private void InitializeComponent() this.chkHotkey.Size = new System.Drawing.Size(73, 17); this.chkHotkey.TabIndex = 2; this.chkHotkey.Text = "F8 hotkey"; - this.toolTip1.SetToolTip(this.chkHotkey, "Enables the F8 hotkey"); this.chkHotkey.UseVisualStyleBackColor = true; this.chkHotkey.CheckedChanged += new System.EventHandler(this.chkHotkey_CheckedChanged); // @@ -107,20 +106,37 @@ private void InitializeComponent() this.chkEnter.Size = new System.Drawing.Size(78, 17); this.chkEnter.TabIndex = 7; this.chkEnter.Text = "Type Enter"; - this.toolTip1.SetToolTip(this.chkEnter, "If set, Type will type newline (\\n) as Enter, which is useful for large blobs of " + - "text.\r\n\r\nIf unset, Type will stop before the first newline, which is useful for " + - "passwords."); this.chkEnter.UseVisualStyleBackColor = true; this.chkEnter.CheckedChanged += new System.EventHandler(this.chkEnter_CheckedChanged); // - // toolTip1 + // tbInterkeyDelay // - this.toolTip1.ShowAlways = true; + this.tbInterkeyDelay.CausesValidation = false; + this.tbInterkeyDelay.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbInterkeyDelay.Location = new System.Drawing.Point(158, 93); + this.tbInterkeyDelay.MaxLength = 5; + this.tbInterkeyDelay.Name = "tbInterkeyDelay"; + this.tbInterkeyDelay.Size = new System.Drawing.Size(55, 22); + this.tbInterkeyDelay.TabIndex = 8; + this.tbInterkeyDelay.Text = "20"; + this.tbInterkeyDelay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // lInterkeyDelay + // + this.lInterkeyDelay.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lInterkeyDelay.Location = new System.Drawing.Point(12, 96); + this.lInterkeyDelay.Name = "lInterkeyDelay"; + this.lInterkeyDelay.Size = new System.Drawing.Size(140, 14); + this.lInterkeyDelay.TabIndex = 9; + this.lInterkeyDelay.Text = "Interkey Delay (ms)"; // // Form1 // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(334, 99); + this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange; + this.ClientSize = new System.Drawing.Size(334, 122); + this.Controls.Add(this.lInterkeyDelay); + this.Controls.Add(this.tbInterkeyDelay); this.Controls.Add(this.chkEnter); this.Controls.Add(this.button3); this.Controls.Add(this.textBox2); @@ -129,6 +145,7 @@ private void InitializeComponent() this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.KeyPreview = true; this.MaximizeBox = false; this.Name = "Form1"; this.ShowIcon = false; @@ -141,9 +158,12 @@ private void InitializeComponent() this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter); this.ResumeLayout(false); this.PerformLayout(); - } + private System.Windows.Forms.Label lInterkeyDelay; + + private System.Windows.Forms.TextBox tbInterkeyDelay; + #endregion private System.Windows.Forms.TextBox textBox1; @@ -153,7 +173,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button3; private System.Windows.Forms.CheckBox chkEnter; - private System.Windows.Forms.ToolTip toolTip1; } } diff --git a/TypeClipboard/Form1.cs b/TypeClipboard/Form1.cs index 8828c42..62116ef 100644 --- a/TypeClipboard/Form1.cs +++ b/TypeClipboard/Form1.cs @@ -7,8 +7,8 @@ namespace TypeClipboard { public partial class Form1 : Form { - const int WS_EX_NOACTIVATE = 0x08000000; - + private const int WS_EX_TOPMOST = 0x00000008; + private LowLevelKeyboardListener _listener; private Typer _tc; @@ -17,6 +17,12 @@ public Form1() InitializeComponent(); Thread.Sleep(100); } + + + protected override bool ShowWithoutActivation + { + get { return true; } + } // // https://stackoverflow.com/questions/2795558/c-sharp-sending-keyboard-events-to-last-selected-window @@ -27,14 +33,19 @@ protected override CreateParams CreateParams get { CreateParams param = base.CreateParams; - param.ExStyle |= WS_EX_NOACTIVATE; + param.ExStyle |= WS_EX_TOPMOST; return param; } } private void button1_Click(object sender, EventArgs e) { - _tc.TypeClipboard(2000); + int delay = 2000; + if (!int.TryParse(tbInterkeyDelay.Text, out int interkeyDelay)) + { + interkeyDelay = 20; + } + _tc.TypeClipboard(interkeyDelay, delay); } public void UpdateTextbox(EventArgs e = null) @@ -127,7 +138,12 @@ private void chkHotkey_CheckedChanged(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e) { - _tc.Type(textBox2.Text); + int delay = 2000; + if (!int.TryParse(tbInterkeyDelay.Text, out int interkeyDelay)) + { + interkeyDelay = 20; + } + _tc.Type(textBox2.Text, interkeyDelay, delay); } private void button3_Click(object sender, EventArgs e) diff --git a/TypeClipboard/Form1.resx b/TypeClipboard/Form1.resx index 69363bf..1af7de1 100644 --- a/TypeClipboard/Form1.resx +++ b/TypeClipboard/Form1.resx @@ -117,13 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - - - 17, 17 - - - 17, 17 - \ No newline at end of file diff --git a/TypeClipboard/LowLevelKeyboardListener.cs b/TypeClipboard/LowLevelKeyboardListener.cs index 2ce19dc..d90e525 100644 --- a/TypeClipboard/LowLevelKeyboardListener.cs +++ b/TypeClipboard/LowLevelKeyboardListener.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Threading; using System.Windows.Input; @@ -92,7 +93,8 @@ private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) if (keyPressed == Key.F8) { // Call Type Clipboard - _tc.TypeClipboard(100); + // ToDo: Implement get values of interkeyDelay and delay from the form + _tc.TypeClipboard(20, 100); // Prevent key bring pressed further into the app return new IntPtr(1); diff --git a/TypeClipboard/Typer.cs b/TypeClipboard/Typer.cs index 4b2b85e..7f25f5a 100644 --- a/TypeClipboard/Typer.cs +++ b/TypeClipboard/Typer.cs @@ -10,12 +10,10 @@ namespace TypeClipboard { class Typer { - private const int INTERKEY_DELAY = 20; - private bool _typeEnter = false; public bool TypeEnter { get => _typeEnter; set => _typeEnter = value; } - public void Type(String str, int delay = 2000) + public void Type(String str, int interkeyDelay = 20, int delay = 2000) { Thread.Sleep(delay); foreach (Char c in str.ToCharArray()) @@ -70,16 +68,16 @@ public void Type(String str, int delay = 2000) SendKeys.Send(c.ToString()); break; } - Thread.Sleep(INTERKEY_DELAY); + Thread.Sleep(interkeyDelay); } } - public void TypeClipboard(int delay = 2000) + public void TypeClipboard(int interkeyDelay = 20, int delay = 2000) { if (Clipboard.ContainsText(TextDataFormat.UnicodeText)) { String clipboard = Clipboard.GetText(TextDataFormat.UnicodeText); - this.Type(clipboard, delay); + this.Type(clipboard, interkeyDelay, delay); } } } diff --git a/screenshot.png b/screenshot.png index 83bd732..712d16c 100644 Binary files a/screenshot.png and b/screenshot.png differ