Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Form Field: "Interkey Delay (ms)" #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions TypeClipboard/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions TypeClipboard/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions TypeClipboard/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,4 @@
<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>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<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>
4 changes: 3 additions & 1 deletion TypeClipboard/LowLevelKeyboardListener.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Input;


Expand Down Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions TypeClipboard/Typer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.