diff --git a/TypeClipboard/Form1.Designer.cs b/TypeClipboard/Form1.Designer.cs index 1cab5c7..3acdcd2 100644 --- a/TypeClipboard/Form1.Designer.cs +++ b/TypeClipboard/Form1.Designer.cs @@ -37,6 +37,9 @@ button3 = new Button(); chkEnter = new CheckBox(); toolTip1 = new ToolTip(components); + label1 = new Label(); + comboBox1 = new ComboBox(); + linkLabel1 = new LinkLabel(); SuspendLayout(); // // textBox1 @@ -115,11 +118,45 @@ // toolTip1.ShowAlways = true; // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 94); + label1.Name = "label1"; + label1.Size = new Size(41, 15); + label1.TabIndex = 8; + label1.Text = "Mode:"; + // + // comboBox1 + // + comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox1.FormattingEnabled = true; + comboBox1.Items.AddRange(new object[] { "SendInput", "SendKeys" }); + comboBox1.Location = new Point(59, 93); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(121, 23); + comboBox1.TabIndex = 9; + comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + // + // linkLabel1 + // + linkLabel1.AutoSize = true; + linkLabel1.Location = new Point(186, 94); + linkLabel1.Name = "linkLabel1"; + linkLabel1.Size = new Size(32, 15); + linkLabel1.TabIndex = 10; + linkLabel1.TabStop = true; + linkLabel1.Text = "Help"; + linkLabel1.LinkClicked += linkLabel1_LinkClicked; + // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(344, 99); + ClientSize = new Size(344, 123); + Controls.Add(linkLabel1); + Controls.Add(comboBox1); + Controls.Add(label1); Controls.Add(chkEnter); Controls.Add(button3); Controls.Add(textBox2); @@ -153,5 +190,8 @@ private Button button3; private CheckBox chkEnter; private ToolTip toolTip1; + private Label label1; + private ComboBox comboBox1; + private LinkLabel linkLabel1; } } diff --git a/TypeClipboard/Form1.cs b/TypeClipboard/Form1.cs index accf73a..eb6b3ce 100644 --- a/TypeClipboard/Form1.cs +++ b/TypeClipboard/Form1.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Text; using System.Threading; using System.Windows.Forms; @@ -97,6 +98,8 @@ namespace TypeClipboard // Changing the chkEnter.Checked property also changes _tc.TypeEnter property chkEnter.Checked = Properties.Settings.Default.enableEnter; + comboBox1.SelectedItem = Properties.Settings.Default.typeMethod; + ClipboardNotification.ClipboardUpdate += delegate (object cb_sender, EventArgs cb_e) { UpdateTextbox(); @@ -142,5 +145,24 @@ namespace TypeClipboard _tc.TypeEnter = chkEnter.Checked; Properties.Settings.Default.Save(); } + + private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + try + { + Process.Start(new ProcessStartInfo { FileName = @"https://github.com/jlaundry/TypeClipboard/wiki/Help", UseShellExecute = true }); + } + catch (Exception ex) + { + MessageBox.Show("Unable to open default browser. Go to https://github.com/jlaundry/TypeClipboard/wiki/Help"); + } + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + Properties.Settings.Default.typeMethod = (string)comboBox1.SelectedItem; + _tc.TypeMethod = (string)comboBox1.SelectedItem; + Properties.Settings.Default.Save(); + } } } diff --git a/TypeClipboard/Form1.resx b/TypeClipboard/Form1.resx index dcfd08d..c87be78 100644 --- a/TypeClipboard/Form1.resx +++ b/TypeClipboard/Form1.resx @@ -120,4 +120,7 @@ 17, 17 + + 17, 17 + \ No newline at end of file diff --git a/TypeClipboard/Properties/Settings.Designer.cs b/TypeClipboard/Properties/Settings.Designer.cs index b0cb55d..43dfcf3 100644 --- a/TypeClipboard/Properties/Settings.Designer.cs +++ b/TypeClipboard/Properties/Settings.Designer.cs @@ -26,25 +26,46 @@ namespace TypeClipboard.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool enableHotkey { - get { + public bool enableHotkey + { + get + { return ((bool)(this["enableHotkey"])); } - set { + set + { this["enableHotkey"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool enableEnter { - get { + public bool enableEnter + { + get + { return ((bool)(this["enableEnter"])); } - set { + set + { this["enableEnter"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("SendInput")] + public string typeMethod + { + get + { + return ((string)(this["typeMethod"])); + } + set + { + this["typeMethod"] = value; + } + } } } diff --git a/TypeClipboard/Typer.cs b/TypeClipboard/Typer.cs index 6d0601d..8c5ac1a 100644 --- a/TypeClipboard/Typer.cs +++ b/TypeClipboard/Typer.cs @@ -9,8 +9,11 @@ namespace TypeClipboard private const int INTERKEY_DELAY = 50; private bool _typeEnter = false; + private string _typeMethod = "SendInput"; public bool TypeEnter { get => _typeEnter; set => _typeEnter = value; } + public string TypeMethod { get => _typeMethod; set => _typeMethod = value; } + public void Type(String str, int delay = 2000) { Thread.Sleep(delay); @@ -18,20 +21,85 @@ namespace TypeClipboard //KeyboardTyper.Reset(); KeyboardTyper.Type(str, _typeEnter, INTERKEY_DELAY); - //KeyboardTyper.Press(Key.LeftShift); - //KeyboardTyper.Type("hello, capitalized world"); - //KeyboardTyper.Release(Key.LeftShift); NativeMethods.BlockInput(false); } + public void TypeWithSendKeys(String str, int delay) + { + Thread.Sleep(delay); + foreach (Char c in str.ToCharArray()) + { + // Some characters have special meaning + // https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement + switch (c) + { + case '\n': + if (_typeEnter) + { + SendKeys.Send("{ENTER}"); + break; + } + else + { + return; + } + case '\r': + if (_typeEnter) + { + break; + } + else + { + return; + } + case '{': + SendKeys.Send("{{}"); + break; + case '}': + SendKeys.Send("{}}"); + break; + case '+': + SendKeys.Send("{+}"); + break; + case '^': + SendKeys.Send("{^}"); + break; + case '%': + SendKeys.Send("{%}"); + break; + case '~': + SendKeys.Send("{~}"); + break; + case '(': + SendKeys.Send("{(}"); + break; + case ')': + SendKeys.Send("{)}"); + break; + default: + SendKeys.Send(c.ToString()); + break; + } + Thread.Sleep(INTERKEY_DELAY); + } + } + public void TypeClipboard(int delay = 2000) { if (Clipboard.ContainsText(TextDataFormat.UnicodeText)) { String clipboard = Clipboard.GetText(TextDataFormat.UnicodeText); - this.Type(clipboard, delay); + if (_typeMethod == "SendKeys") + { + TypeWithSendKeys(clipboard, delay); + } + else + { + // SendInput is default + Type(clipboard, delay); + } } } }