Skip to content

Commit

Permalink
Merge pull request #1 from ShayanFiroozi/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ShayanFiroozi authored Apr 6, 2024
2 parents 53fc23e + 5b4159b commit fda055a
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 62 deletions.
58 changes: 8 additions & 50 deletions BackEnd/KeyboardSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,25 @@

namespace FluentTypeSimulator.BackEnd
{
internal static class KeyboardSimulator
internal static class KeyBoardSimulator
{

public static void PressEnter() => SendKeys.Send("{ENTER}");

public static async Task SimulateTyping(string TextToType, int KeyPressDelayInMilliSeconds, int NewLineDelayInMilliSedonds)
{
char[] CharsToType = Parser.ParseString(TextToType);
public static void PressSpace() => SendKeys.Send(" ");

if (CharsToType.Length == 0)
{
throw new Exception("No word to type !");
}
public static void PressCTRL_A(string character) => PressCTRLWithACharacter("a");

foreach (char character in CharsToType)
{
await SimulateKeyPress(character, NewLineDelayInMilliSedonds);
public static void PressCTRL_C(string character) => PressCTRLWithACharacter("c");

if (NewLineDelayInMilliSedonds > 0)
{
await Task.Delay(KeyPressDelayInMilliSeconds);
}
}
public static void PressCTRL_V() => PressCTRLWithACharacter("v");

}

private static async Task SimulateKeyPress(char character, int NewLineDelayInMilliSedonds)
{

switch (character)
{
case '\n':
// Simulate pressing Enter
SendKeys.Send("{ENTER}");
await Task.Delay(NewLineDelayInMilliSedonds);
break;

case ' ':
// Simulate pressing Space
SendKeys.Send(" ");
break;
default:
// Simulate other character

if (char.IsLetter(character) || char.IsDigit(character) || char.IsNumber(character))
{
// Letter or number characters
SendKeys.Send(character.ToString());
}
else
{
// Special characters
SendKeys.Send($"{{{character}}}");
}

break;
}
}

public static void PressSpecialCharacter(string character) => SendKeys.Send($"{{{character}}}");



public static void PressCTRLWithACharacter(string character) => SendKeys.Send($"^{character}");

}
}
19 changes: 15 additions & 4 deletions BackEnd/Parser.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
using System;
using System.Linq;
using System.Windows.Forms;

namespace FluentTypeSimulator.BackEnd
{


internal static class Parser
{
public static char[] ParseString(string inputData)
public static char[] StringToCharArray(string inputData)
{
if (string.IsNullOrWhiteSpace(inputData))
{
throw new ArgumentException($"'{nameof(inputData)}' cannot be null or whitespace.", nameof(inputData));
}

return inputData.ToCharArray().Where(c => c != '\r').ToArray();
}



}
public static string[] StringToStringArray(string inputData)
{
if (string.IsNullOrWhiteSpace(inputData))
{
throw new ArgumentException($"'{nameof(inputData)}' cannot be null or whitespace.", nameof(inputData));
}

return inputData.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
}


}



}
70 changes: 70 additions & 0 deletions BackEnd/TypeSimulator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FluentTypeSimulator.BackEnd
{
internal static class TypeSimulator
{


public static async Task SimulateTyping(string TextToType, int KeyPressDelayInMilliSeconds, int NewLineDelayInMilliSedonds)
{
char[] CharsToType = Parser.StringToCharArray(TextToType);

if (CharsToType.Length == 0)
{
throw new Exception("No word to type !");
}

foreach (char character in CharsToType)
{
await SimulateKeyPress(character, NewLineDelayInMilliSedonds);

if (KeyPressDelayInMilliSeconds > 0)
{
await Task.Delay(KeyPressDelayInMilliSeconds);
}
}

}

private static async Task SimulateKeyPress(char character, int NewLineDelayInMilliSedonds)
{

switch (character)
{
case '\n':
// Simulate pressing Enter
KeyBoardSimulator.PressEnter();
await Task.Delay(NewLineDelayInMilliSedonds);
break;

case ' ':
// Simulate pressing Space
KeyBoardSimulator.PressSpace();
break;
default:
// Simulate other character

if (char.IsLetter(character) || char.IsDigit(character) || char.IsNumber(character))
{
// Letter or number characters
SendKeys.Send(character.ToString());
}
else
{
// Special characters
KeyBoardSimulator.PressSpecialCharacter(character.ToString());
}

break;
}
}





}
}
66 changes: 66 additions & 0 deletions BackEnd/TypeSimulatorCopyPasteMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FluentTypeSimulator.BackEnd
{
internal static class TypeSimulatorCopyPasteMode
{


public static async Task StartCopyPasting(string TextToCopyPaste, int NewLineDelayInMilliSedonds)
{
string[] LinesToCopyPaste = Parser.StringToStringArray(TextToCopyPaste);

if (LinesToCopyPaste.Length == 0)
{
throw new Exception("No lines to copy/paste !");
}

foreach (string line in LinesToCopyPaste)
{
// Handle the wmpty lines
if (string.IsNullOrEmpty(line))
{
KeyBoardSimulator.PressEnter();

if (NewLineDelayInMilliSedonds > 0)
{
await Task.Delay(NewLineDelayInMilliSedonds);
}
continue;
}


// Put the line to clipboard
Clipboard.Clear();
Clipboard.SetText(line);

// Paste Data from clipboard
KeyBoardSimulator.PressCTRL_V();


// Go to the new linw
KeyBoardSimulator.PressEnter();

if (NewLineDelayInMilliSedonds > 0)
{
await Task.Delay(NewLineDelayInMilliSedonds);
}



}

}






}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# FluentTypeSimulator Change Log :


Test

## ✔ 1.0
* Change log created !
63 changes: 61 additions & 2 deletions UI/FrmMain.Designer.cs

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

Loading

0 comments on commit fda055a

Please sign in to comment.