restore SendKeys as an option
This commit is contained in:
69
TypeClipboard/Form1.Designer.cs
generated
69
TypeClipboard/Form1.Designer.cs
generated
@@ -1,4 +1,7 @@
|
||||
namespace TypeClipboard
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TypeClipboard
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
@@ -23,14 +26,12 @@
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.chkHotkey = new System.Windows.Forms.CheckBox();
|
||||
@@ -39,6 +40,8 @@
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.chkEnter = new System.Windows.Forms.CheckBox();
|
||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBox1
|
||||
@@ -63,7 +66,7 @@
|
||||
// chkHotkey
|
||||
//
|
||||
this.chkHotkey.AutoSize = true;
|
||||
this.chkHotkey.Location = new System.Drawing.Point(172, 42);
|
||||
this.chkHotkey.Location = new System.Drawing.Point(102, 98);
|
||||
this.chkHotkey.Name = "chkHotkey";
|
||||
this.chkHotkey.Size = new System.Drawing.Size(73, 17);
|
||||
this.chkHotkey.TabIndex = 2;
|
||||
@@ -104,7 +107,7 @@
|
||||
// chkEnter
|
||||
//
|
||||
this.chkEnter.AutoSize = true;
|
||||
this.chkEnter.Location = new System.Drawing.Point(244, 42);
|
||||
this.chkEnter.Location = new System.Drawing.Point(177, 98);
|
||||
this.chkEnter.Name = "chkEnter";
|
||||
this.chkEnter.Size = new System.Drawing.Size(78, 17);
|
||||
this.chkEnter.TabIndex = 7;
|
||||
@@ -119,10 +122,39 @@
|
||||
//
|
||||
this.toolTip1.ShowAlways = true;
|
||||
//
|
||||
// comboBox1
|
||||
//
|
||||
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBox1.FormattingEnabled = true;
|
||||
this.comboBox1.Items.AddRange(new object[] {
|
||||
"SendInput",
|
||||
"SendKeys"});
|
||||
this.comboBox1.Location = new System.Drawing.Point(12, 95);
|
||||
this.comboBox1.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.comboBox1.Name = "comboBox1";
|
||||
this.comboBox1.Size = new System.Drawing.Size(82, 21);
|
||||
this.comboBox1.TabIndex = 9;
|
||||
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
|
||||
//
|
||||
// linkLabel1
|
||||
//
|
||||
this.linkLabel1.AutoSize = true;
|
||||
this.linkLabel1.Location = new System.Drawing.Point(293, 98);
|
||||
this.linkLabel1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
|
||||
this.linkLabel1.Name = "linkLabel1";
|
||||
this.linkLabel1.Size = new System.Drawing.Size(29, 13);
|
||||
this.linkLabel1.TabIndex = 10;
|
||||
this.linkLabel1.TabStop = true;
|
||||
this.linkLabel1.Text = "Help";
|
||||
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(334, 99);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(332, 124);
|
||||
this.Controls.Add(this.linkLabel1);
|
||||
this.Controls.Add(this.comboBox1);
|
||||
this.Controls.Add(this.chkEnter);
|
||||
this.Controls.Add(this.button3);
|
||||
this.Controls.Add(this.textBox2);
|
||||
@@ -148,14 +180,15 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.CheckBox chkHotkey;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.TextBox textBox2;
|
||||
private System.Windows.Forms.Button button3;
|
||||
private System.Windows.Forms.CheckBox chkEnter;
|
||||
private System.Windows.Forms.ToolTip toolTip1;
|
||||
private TextBox textBox1;
|
||||
private Button button1;
|
||||
private CheckBox chkHotkey;
|
||||
private Button button2;
|
||||
private TextBox textBox2;
|
||||
private Button button3;
|
||||
private CheckBox chkEnter;
|
||||
private ToolTip toolTip1;
|
||||
private ComboBox comboBox1;
|
||||
private LinkLabel linkLabel1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
@@ -97,7 +98,10 @@ namespace TypeClipboard
|
||||
// Changing the chkEnter.Checked property also changes _tc.TypeEnter property
|
||||
chkEnter.Checked = Properties.Settings.Default.enableEnter;
|
||||
|
||||
ClipboardNotification.ClipboardUpdate += delegate (object cb_sender, EventArgs cb_e) {
|
||||
comboBox1.SelectedItem = Properties.Settings.Default.typeMethod;
|
||||
|
||||
ClipboardNotification.ClipboardUpdate += delegate (object cb_sender, EventArgs cb_e)
|
||||
{
|
||||
UpdateTextbox();
|
||||
};
|
||||
UpdateTextbox();
|
||||
@@ -141,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
123
TypeClipboard/Form1.resx
Normal file
123
TypeClipboard/Form1.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
35
TypeClipboard/Properties/Settings.Designer.cs
generated
35
TypeClipboard/Properties/Settings.Designer.cs
generated
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
<ApplicationVersion>1.6.0.0</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
|
||||
<ForceDesignerDpiUnaware>true</ForceDesignerDpiUnaware>
|
||||
<!-- Otherwise System.Windows.Input has no methods in .NET 8... -->
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@@ -77,6 +79,9 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Typer.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -17,8 +17,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);
|
||||
@@ -26,20 +29,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user