Added Automate stop support, line delay setting

This commit is contained in:
Jaex 2015-02-17 12:46:00 +02:00
parent 806d55b5e1
commit 154514c8c3
13 changed files with 185 additions and 80 deletions

View file

@ -38,18 +38,23 @@ private void InitializeComponent()
this.btnSaveScript = new System.Windows.Forms.Button();
this.lblScriptName = new System.Windows.Forms.Label();
this.btnRemoveScript = new System.Windows.Forms.Button();
this.btnAddMouseMove = new System.Windows.Forms.Button();
this.lblLineDelay = new System.Windows.Forms.Label();
this.nudLineDelay = new System.Windows.Forms.NumericUpDown();
this.lblLineDelayMiliseconds = new System.Windows.Forms.Label();
this.lvScripts = new ShareX.HelpersLib.MyListView();
this.chScriptName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.pInput.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudLineDelay)).BeginInit();
this.SuspendLayout();
//
// btnRun
//
this.btnRun.Location = new System.Drawing.Point(9, 9);
this.btnRun.Name = "btnRun";
this.btnRun.Size = new System.Drawing.Size(120, 39);
this.btnRun.Size = new System.Drawing.Size(120, 63);
this.btnRun.TabIndex = 1;
this.btnRun.Text = "Run";
this.btnRun.Text = "Start";
this.btnRun.UseVisualStyleBackColor = true;
this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
//
@ -60,7 +65,7 @@ private void InitializeComponent()
this.rtbInput.Font = new System.Drawing.Font("Verdana", 12F);
this.rtbInput.Location = new System.Drawing.Point(3, 3);
this.rtbInput.Name = "rtbInput";
this.rtbInput.Size = new System.Drawing.Size(496, 416);
this.rtbInput.Size = new System.Drawing.Size(496, 392);
this.rtbInput.TabIndex = 0;
this.rtbInput.Text = "";
this.rtbInput.TextChanged += new System.EventHandler(this.rtbInput_TextChanged);
@ -70,10 +75,10 @@ private void InitializeComponent()
this.pInput.BackColor = System.Drawing.Color.White;
this.pInput.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pInput.Controls.Add(this.rtbInput);
this.pInput.Location = new System.Drawing.Point(8, 56);
this.pInput.Location = new System.Drawing.Point(8, 80);
this.pInput.Name = "pInput";
this.pInput.Padding = new System.Windows.Forms.Padding(3);
this.pInput.Size = new System.Drawing.Size(504, 424);
this.pInput.Size = new System.Drawing.Size(504, 400);
this.pInput.TabIndex = 0;
//
// cbFunctions
@ -96,9 +101,9 @@ private void InitializeComponent()
//
// btnLoadExample
//
this.btnLoadExample.Location = new System.Drawing.Point(137, 9);
this.btnLoadExample.Location = new System.Drawing.Point(520, 96);
this.btnLoadExample.Name = "btnLoadExample";
this.btnLoadExample.Size = new System.Drawing.Size(120, 39);
this.btnLoadExample.Size = new System.Drawing.Size(152, 24);
this.btnLoadExample.TabIndex = 2;
this.btnLoadExample.Text = "Load example";
this.btnLoadExample.UseVisualStyleBackColor = true;
@ -140,6 +145,52 @@ private void InitializeComponent()
this.btnRemoveScript.UseVisualStyleBackColor = true;
this.btnRemoveScript.Click += new System.EventHandler(this.btnRemoveScript_Click);
//
// btnAddMouseMove
//
this.btnAddMouseMove.Location = new System.Drawing.Point(344, 48);
this.btnAddMouseMove.Name = "btnAddMouseMove";
this.btnAddMouseMove.Size = new System.Drawing.Size(168, 23);
this.btnAddMouseMove.TabIndex = 10;
this.btnAddMouseMove.Text = "Add mouse move";
this.btnAddMouseMove.UseVisualStyleBackColor = true;
this.btnAddMouseMove.Click += new System.EventHandler(this.btnAddMouseMove_Click);
//
// lblLineDelay
//
this.lblLineDelay.AutoSize = true;
this.lblLineDelay.Location = new System.Drawing.Point(136, 8);
this.lblLineDelay.Name = "lblLineDelay";
this.lblLineDelay.Size = new System.Drawing.Size(58, 13);
this.lblLineDelay.TabIndex = 11;
this.lblLineDelay.Text = "Line delay:";
//
// nudLineDelay
//
this.nudLineDelay.Increment = new decimal(new int[] {
100,
0,
0,
0});
this.nudLineDelay.Location = new System.Drawing.Point(137, 25);
this.nudLineDelay.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.nudLineDelay.Name = "nudLineDelay";
this.nudLineDelay.Size = new System.Drawing.Size(87, 20);
this.nudLineDelay.TabIndex = 12;
this.nudLineDelay.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// lblLineDelayMiliseconds
//
this.lblLineDelayMiliseconds.AutoSize = true;
this.lblLineDelayMiliseconds.Location = new System.Drawing.Point(230, 29);
this.lblLineDelayMiliseconds.Name = "lblLineDelayMiliseconds";
this.lblLineDelayMiliseconds.Size = new System.Drawing.Size(20, 13);
this.lblLineDelayMiliseconds.TabIndex = 13;
this.lblLineDelayMiliseconds.Text = "ms";
//
// lvScripts
//
this.lvScripts.AutoFillColumn = true;
@ -148,10 +199,10 @@ private void InitializeComponent()
this.lvScripts.FullRowSelect = true;
this.lvScripts.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.lvScripts.HideSelection = false;
this.lvScripts.Location = new System.Drawing.Point(520, 104);
this.lvScripts.Location = new System.Drawing.Point(520, 128);
this.lvScripts.MultiSelect = false;
this.lvScripts.Name = "lvScripts";
this.lvScripts.Size = new System.Drawing.Size(152, 376);
this.lvScripts.Size = new System.Drawing.Size(152, 352);
this.lvScripts.TabIndex = 5;
this.lvScripts.UseCompatibleStateImageBehavior = false;
this.lvScripts.View = System.Windows.Forms.View.Details;
@ -167,6 +218,10 @@ private void InitializeComponent()
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(683, 489);
this.Controls.Add(this.lblLineDelayMiliseconds);
this.Controls.Add(this.nudLineDelay);
this.Controls.Add(this.lblLineDelay);
this.Controls.Add(this.btnAddMouseMove);
this.Controls.Add(this.btnRemoveScript);
this.Controls.Add(this.lblScriptName);
this.Controls.Add(this.btnSaveScript);
@ -181,6 +236,7 @@ private void InitializeComponent()
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - Automate";
this.pInput.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.nudLineDelay)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -200,6 +256,10 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblScriptName;
private System.Windows.Forms.Button btnRemoveScript;
private System.Windows.Forms.ColumnHeader chScriptName;
private System.Windows.Forms.Button btnAddMouseMove;
private System.Windows.Forms.Label lblLineDelay;
private System.Windows.Forms.NumericUpDown nudLineDelay;
private System.Windows.Forms.Label lblLineDelayMiliseconds;

View file

@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace ShareX.HelpersLib
@ -36,10 +37,10 @@ namespace ShareX.HelpersLib
public partial class AutomateForm : Form
{
public List<ScriptInfo> Scripts { get; private set; }
public bool IsWorking { get; private set; }
private FunctionManager functionManager = new FunctionManager();
private Tokenizer tokenizer = new Tokenizer();
private bool isWorking;
public AutomateForm(List<ScriptInfo> scripts)
{
@ -123,13 +124,14 @@ private void SyntaxHighlighting(List<Token> tokens)
rtbInput.EndUpdate();
}
private void btnRun_Click(object sender, EventArgs e)
private void Start()
{
if (!isWorking)
if (!IsWorking)
{
isWorking = true;
btnRun.Enabled = false;
IsWorking = true;
btnRun.Text = Resources.Stop;
string[] lines = rtbInput.Lines;
functionManager.LineDelay = (int)nudLineDelay.Value;
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
@ -137,6 +139,31 @@ private void btnRun_Click(object sender, EventArgs e)
}
}
private void Stop()
{
if (IsWorking)
{
functionManager.Stop();
btnRun.Text = Resources.Start;
IsWorking = false;
}
}
private void btnRun_Click(object sender, EventArgs e)
{
lock (this)
{
if (IsWorking)
{
Stop();
}
else
{
Start();
}
}
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
string[] lines = e.Argument as string[];
@ -148,14 +175,13 @@ private void bw_DoWork(object sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.ExportImportControl_Serialize_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
isWorking = false;
btnRun.Enabled = true;
Stop();
}
private void btnLoadExample_Click(object sender, EventArgs e)
@ -166,13 +192,13 @@ Call MouseFunctions
3 Call LoopTest
5 KeyPress return
Func KeyboardFunctions
Function KeyboardFunctions
KeyDown space
KeyUp space
KeyPress key_a
KeyPressText ""Test 123""
Func MouseFunctions
Function MouseFunctions
MouseMove 300 250
MouseDown left
MouseUp left
@ -180,7 +206,7 @@ MouseClick right
MouseClick 100 450 left
MouseWheel 120
Func LoopTest
Function LoopTest
Wait 1000
KeyPressText ""Loop""";
}
@ -191,7 +217,7 @@ private void btnSaveScript_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(scriptName))
{
MessageBox.Show("Script name can't be empty.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show("Script name can't be empty.", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
@ -200,10 +226,16 @@ private void btnSaveScript_Click(object sender, EventArgs e)
if (scriptInfo != null)
{
scriptInfo.Script = rtbInput.Text;
scriptInfo.LineDelay = (int)nudLineDelay.Value;
}
else
{
scriptInfo = new ScriptInfo(scriptName, rtbInput.Text);
scriptInfo = new ScriptInfo()
{
Name = scriptName,
Script = rtbInput.Text,
LineDelay = (int)nudLineDelay.Value
};
Scripts.Add(scriptInfo);
AddScript(scriptInfo);
}
@ -231,9 +263,25 @@ private void lvScripts_SelectedIndexChanged(object sender, EventArgs e)
{
txtScriptName.Text = scriptInfo.Name;
rtbInput.Text = scriptInfo.Script;
nudLineDelay.Value = scriptInfo.LineDelay;
Tokenize();
}
}
}
private void btnAddMouseMove_Click(object sender, EventArgs e)
{
Thread thread = new Thread(() =>
{
Thread.Sleep(1000);
Point position = Cursor.Position;
this.InvokeSafe(() =>
{
rtbInput.SelectedText = string.Format("MouseMove {0} {1}", position.X, position.Y);
});
});
thread.Start();
}
}
}

View file

@ -34,7 +34,7 @@ public class FunctionManager
{
public static readonly Dictionary<string, Type> Functions = new Dictionary<string, Type>()
{
{ "Func", typeof(Function) },
{ "Function", typeof(Function) },
{ "Call", typeof(Function_Call) },
{ "Wait", typeof(Function_Wait) },
{ "KeyDown", typeof(Function_KeyDown) },
@ -137,6 +137,8 @@ public void Run(int startIndex = 0)
{
if (FunctionList != null)
{
stopRequest = false;
Function function;
for (int i = startIndex; i < FunctionList.Count && !stopRequest; i++)

View file

@ -34,11 +34,6 @@ public class ScriptInfo
{
public string Name { get; set; }
public string Script { get; set; }
public ScriptInfo(string name, string script)
{
Name = name;
Script = script;
}
public int LineDelay { get; set; }
}
}

View file

@ -78,7 +78,7 @@ private string Serialize(object obj)
catch (Exception e)
{
DebugHelper.WriteException(e);
MessageBox.Show(Resources.ExportImportControl_Serialize_Export_failed_ + "\n\n" + e, "ShareX - " + Resources.ExportImportControl_Serialize_Error,
MessageBox.Show(Resources.ExportImportControl_Serialize_Export_failed_ + "\n\n" + e, "ShareX - " + Resources.Error,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -154,7 +154,7 @@ private object Deserialize(string json)
catch (Exception e)
{
DebugHelper.WriteException(e);
MessageBox.Show(Resources.ExportImportControl_Deserialize_Import_failed_ + "\n\n" + e, "ShareX - " + Resources.ExportImportControl_Serialize_Error,
MessageBox.Show(Resources.ExportImportControl_Deserialize_Import_failed_ + "\n\n" + e, "ShareX - " + Resources.Error,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

View file

@ -64,7 +64,7 @@ private void btnStartHashCheck_Click(object sender, EventArgs e)
if (hashCheck.Start(txtFilePath.Text, hashType))
{
btnStartHashCheck.Text = Resources.HashCheckForm_btnStartHashCheck_Click_Stop;
btnStartHashCheck.Text = Resources.Stop;
txtResult.Text = string.Empty;
}
}
@ -78,7 +78,7 @@ private void fileCheck_FileCheckProgressChanged(float progress)
private void fileCheck_FileCheckCompleted(string result, bool cancelled)
{
btnStartHashCheck.Text = Resources.HashCheckForm_fileCheck_FileCheckCompleted_Start;
btnStartHashCheck.Text = Resources.Start;
txtResult.Text = result.ToUpperInvariant();
if (!string.IsNullOrEmpty(txtTarget.Text))
{

View file

@ -456,6 +456,15 @@ internal static string DownloaderForm_StartDownload_Getting_file_size_ {
}
}
/// <summary>
/// Looks up a localized string similar to Error.
/// </summary>
internal static string Error {
get {
return ResourceManager.GetString("Error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Browse for executable....
/// </summary>
@ -474,15 +483,6 @@ internal static string ExportImportControl_Deserialize_Import_failed_ {
}
}
/// <summary>
/// Looks up a localized string similar to Error.
/// </summary>
internal static string ExportImportControl_Serialize_Error {
get {
return ResourceManager.GetString("ExportImportControl_Serialize_Error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Export failed..
/// </summary>
@ -654,24 +654,6 @@ internal static string HashCheckForm_btnFilePathBrowse_Click_Choose_file_path {
}
}
/// <summary>
/// Looks up a localized string similar to Stop.
/// </summary>
internal static string HashCheckForm_btnStartHashCheck_Click_Stop {
get {
return ResourceManager.GetString("HashCheckForm_btnStartHashCheck_Click_Stop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Start.
/// </summary>
internal static string HashCheckForm_fileCheck_FileCheckCompleted_Start {
get {
return ResourceManager.GetString("HashCheckForm_fileCheck_FileCheckCompleted_Start", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not create directory, check your path settings..
/// </summary>
@ -1495,6 +1477,24 @@ internal static System.Drawing.Bitmap ShareX_Logo_Black {
}
}
/// <summary>
/// Looks up a localized string similar to Start.
/// </summary>
internal static string Start {
get {
return ResourceManager.GetString("Start", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Stop.
/// </summary>
internal static string Stop {
get {
return ResourceManager.GetString("Stop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Automatic.
/// </summary>

View file

@ -248,7 +248,7 @@ Dateigröße: {2:n0} / {3:n0} KB</value>
<data name="ExportImportControl_Deserialize_Import_failed_" xml:space="preserve">
<value>Import fehlgeschlagen.</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>Fehler</value>
</data>
<data name="ExportImportControl_Serialize_Export_failed_" xml:space="preserve">
@ -308,10 +308,10 @@ Dateigröße: {2:n0} / {3:n0} KB</value>
<data name="HashCheckForm_btnFilePathBrowse_Click_Choose_file_path" xml:space="preserve">
<value>Dateipfad auswählen</value>
</data>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>Anhalten</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>Start</value>
</data>
<data name="Helpers_DownloadString_Download_failed_" xml:space="preserve">

View file

@ -1,4 +1,4 @@
<root>
<root>
<!--
Microsoft ResX Schema
@ -327,7 +327,7 @@ Voulez-vous la télécharger et l'installer?</value>
<data name="URLSharingServices_Email" xml:space="preserve">
<value>Email</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>Erreur</value>
</data>
<data name="ExportImportControl_Serialize_Export_failed_" xml:space="preserve">
@ -426,13 +426,13 @@ Voulez-vous la télécharger et l'installer?</value>
<data name="ReplCodeMenuEntry_un_User_name" xml:space="preserve">
<value>Nom d'utilisateur</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>Démarrer</value>
</data>
<data name="DownloaderForm_ChangeStatus_Status___0_" xml:space="preserve">
<value>Statut: {0}</value>
</data>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>Arrêter</value>
</data>
<data name="AfterCaptureTasks_AnnotateImage" xml:space="preserve">

View file

@ -248,7 +248,7 @@ Fájlméret: {2:n0} / {3:n0} KB</value>
<data name="ExportImportControl_Deserialize_Import_failed_" xml:space="preserve">
<value>Sikertelen importálás.</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>Hiba</value>
</data>
<data name="ExportImportControl_Serialize_Export_failed_" xml:space="preserve">
@ -308,10 +308,10 @@ Fájlméret: {2:n0} / {3:n0} KB</value>
<data name="HashCheckForm_btnFilePathBrowse_Click_Choose_file_path" xml:space="preserve">
<value>Fájl elérési út választása</value>
</data>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>Leállítás</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>Indítás</value>
</data>
<data name="Helpers_DownloadString_Download_failed_" xml:space="preserve">

View file

@ -235,7 +235,7 @@
<data name="HashCheckForm_btnFilePathBrowse_Click_Choose_file_path" xml:space="preserve">
<value>Choose file path</value>
</data>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>Stop</value>
</data>
<data name="ClipboardContentViewer_ClipboardContentViewer_Load_Clipboard_content__Image__Size___0_x_1__" xml:space="preserve">
@ -274,7 +274,7 @@
<data name="FolderSelectDialog_Title_Select_a_folder" xml:space="preserve">
<value>Select a folder</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>Start</value>
</data>
<data name="PrintForm_LoadSettings_Print" xml:space="preserve">
@ -283,7 +283,7 @@
<data name="ExportImportControl_Serialize_Export_failed_" xml:space="preserve">
<value>Export failed.</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="ExportImportControl_tsmiExportClipboard_Click_Settings_copied_to_your_clipboard_" xml:space="preserve">

View file

@ -117,10 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>Durdur</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>Başlat</value>
</data>
<data name="ActionsCodeMenuEntry_FilePath_File_path" xml:space="preserve">
@ -156,7 +156,7 @@
<data name="DownloaderForm_StartDownload_Getting_file_size_" xml:space="preserve">
<value>Dosya boyutu alınıyor.</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>Hata</value>
</data>
<data name="Extensions_AddContextMenu_Copy" xml:space="preserve">

View file

@ -1,4 +1,4 @@
<root>
<root>
<!--
Microsoft ResX Schema
@ -247,7 +247,7 @@
<data name="ExportImportControl_Deserialize_Import_failed_" xml:space="preserve">
<value>导入失败.</value>
</data>
<data name="ExportImportControl_Serialize_Error" xml:space="preserve">
<data name="Error" xml:space="preserve">
<value>错误</value>
</data>
<data name="ExportImportControl_Serialize_Export_failed_" xml:space="preserve">
@ -307,10 +307,10 @@
<data name="HashCheckForm_btnFilePathBrowse_Click_Choose_file_path" xml:space="preserve">
<value>选择文件路径</value>
</data>
<data name="HashCheckForm_btnStartHashCheck_Click_Stop" xml:space="preserve">
<data name="Stop" xml:space="preserve">
<value>停止</value>
</data>
<data name="HashCheckForm_fileCheck_FileCheckCompleted_Start" xml:space="preserve">
<data name="Start" xml:space="preserve">
<value>开始</value>
</data>
<data name="Helpers_DownloadString_Download_failed_" xml:space="preserve">