diff --git a/VAR.ScreenAutomation/FrmAutomationBotParams.cs b/VAR.ScreenAutomation/FrmAutomationBotParams.cs index 22e58bb..2647ed8 100644 --- a/VAR.ScreenAutomation/FrmAutomationBotParams.cs +++ b/VAR.ScreenAutomation/FrmAutomationBotParams.cs @@ -33,9 +33,11 @@ namespace VAR.ScreenAutomation { a.NewObject = new Pair { Parent = pairs }; }; - dgvParams = new DataGridView(); - dgvParams.Dock = DockStyle.Fill; - dgvParams.DataSource = pairs; + dgvParams = new DataGridView + { + Dock = DockStyle.Fill, + DataSource = pairs + }; Controls.Add(dgvParams); } diff --git a/VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs b/VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs index 9140fe1..c033591 100644 --- a/VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs +++ b/VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs @@ -31,12 +31,14 @@ this.picCapturer = new System.Windows.Forms.PictureBox(); this.splitMain = new System.Windows.Forms.SplitContainer(); this.splitOutput = new System.Windows.Forms.SplitContainer(); + this.btnAutomationBotConfig = new System.Windows.Forms.Button(); this.numFPS = new System.Windows.Forms.NumericUpDown(); this.ddlAutomationBot = new System.Windows.Forms.ComboBox(); this.btnStartEnd = new System.Windows.Forms.Button(); - this.btnAutomationBotConfig = new System.Windows.Forms.Button(); + this.chkKeepToplevel = new System.Windows.Forms.CheckBox(); this.picPreview = new VAR.ScreenAutomation.Controls.CtrImageViewer(); this.ctrOutput = new VAR.ScreenAutomation.Controls.CtrOutput(); + this.chkClick = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.picCapturer)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitMain)).BeginInit(); this.splitMain.Panel1.SuspendLayout(); @@ -55,10 +57,11 @@ this.picCapturer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.picCapturer.Location = new System.Drawing.Point(3, 3); + this.picCapturer.Location = new System.Drawing.Point(4, 4); + this.picCapturer.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.picCapturer.Name = "picCapturer"; - this.picCapturer.Padding = new System.Windows.Forms.Padding(8, 8, 8, 8); - this.picCapturer.Size = new System.Drawing.Size(319, 649); + this.picCapturer.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10); + this.picCapturer.Size = new System.Drawing.Size(505, 799); this.picCapturer.TabIndex = 0; this.picCapturer.TabStop = false; // @@ -67,7 +70,7 @@ this.splitMain.Dock = System.Windows.Forms.DockStyle.Fill; this.splitMain.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; this.splitMain.Location = new System.Drawing.Point(0, 0); - this.splitMain.Margin = new System.Windows.Forms.Padding(8, 8, 8, 8); + this.splitMain.Margin = new System.Windows.Forms.Padding(11, 10, 11, 10); this.splitMain.Name = "splitMain"; // // splitMain.Panel1 @@ -77,16 +80,15 @@ // splitMain.Panel2 // this.splitMain.Panel2.Controls.Add(this.picCapturer); - this.splitMain.Size = new System.Drawing.Size(566, 663); + this.splitMain.Size = new System.Drawing.Size(755, 816); this.splitMain.SplitterDistance = 232; - this.splitMain.SplitterWidth = 3; this.splitMain.TabIndex = 3; // // splitOutput // this.splitOutput.Dock = System.Windows.Forms.DockStyle.Fill; this.splitOutput.Location = new System.Drawing.Point(0, 0); - this.splitOutput.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitOutput.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.splitOutput.Name = "splitOutput"; this.splitOutput.Orientation = System.Windows.Forms.Orientation.Horizontal; // @@ -96,21 +98,34 @@ // // splitOutput.Panel2 // + this.splitOutput.Panel2.Controls.Add(this.chkClick); + this.splitOutput.Panel2.Controls.Add(this.chkKeepToplevel); this.splitOutput.Panel2.Controls.Add(this.btnAutomationBotConfig); this.splitOutput.Panel2.Controls.Add(this.numFPS); this.splitOutput.Panel2.Controls.Add(this.ddlAutomationBot); this.splitOutput.Panel2.Controls.Add(this.btnStartEnd); this.splitOutput.Panel2.Controls.Add(this.ctrOutput); - this.splitOutput.Size = new System.Drawing.Size(232, 663); - this.splitOutput.SplitterDistance = 229; - this.splitOutput.SplitterWidth = 3; + this.splitOutput.Size = new System.Drawing.Size(232, 816); + this.splitOutput.SplitterDistance = 281; this.splitOutput.TabIndex = 4; // + // btnAutomationBotConfig + // + this.btnAutomationBotConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnAutomationBotConfig.Location = new System.Drawing.Point(172, 4); + this.btnAutomationBotConfig.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.btnAutomationBotConfig.Name = "btnAutomationBotConfig"; + this.btnAutomationBotConfig.Size = new System.Drawing.Size(60, 28); + this.btnAutomationBotConfig.TabIndex = 6; + this.btnAutomationBotConfig.Text = "Cfg."; + this.btnAutomationBotConfig.UseVisualStyleBackColor = true; + this.btnAutomationBotConfig.Click += new System.EventHandler(this.BtnAutomationBotConfig_Click); + // // numFPS // this.numFPS.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.numFPS.Location = new System.Drawing.Point(186, 41); - this.numFPS.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.numFPS.Location = new System.Drawing.Point(171, 50); + this.numFPS.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.numFPS.Maximum = new decimal(new int[] { 60, 0, @@ -122,7 +137,7 @@ 0, 0}); this.numFPS.Name = "numFPS"; - this.numFPS.Size = new System.Drawing.Size(44, 20); + this.numFPS.Size = new System.Drawing.Size(59, 22); this.numFPS.TabIndex = 5; this.numFPS.Value = new decimal(new int[] { 20, @@ -136,10 +151,10 @@ | System.Windows.Forms.AnchorStyles.Right))); this.ddlAutomationBot.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ddlAutomationBot.FormattingEnabled = true; - this.ddlAutomationBot.Location = new System.Drawing.Point(10, 3); - this.ddlAutomationBot.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ddlAutomationBot.Location = new System.Drawing.Point(13, 4); + this.ddlAutomationBot.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.ddlAutomationBot.Name = "ddlAutomationBot"; - this.ddlAutomationBot.Size = new System.Drawing.Size(171, 21); + this.ddlAutomationBot.Size = new System.Drawing.Size(150, 24); this.ddlAutomationBot.TabIndex = 4; this.ddlAutomationBot.SelectedIndexChanged += new System.EventHandler(this.DdlAutomationBot_SelectedIndexChanged); // @@ -148,25 +163,26 @@ this.btnStartEnd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.btnStartEnd.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnStartEnd.Location = new System.Drawing.Point(11, 28); - this.btnStartEnd.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnStartEnd.Location = new System.Drawing.Point(15, 34); + this.btnStartEnd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.btnStartEnd.Name = "btnStartEnd"; - this.btnStartEnd.Size = new System.Drawing.Size(170, 32); + this.btnStartEnd.Size = new System.Drawing.Size(105, 39); this.btnStartEnd.TabIndex = 3; this.btnStartEnd.Text = "Start"; this.btnStartEnd.UseVisualStyleBackColor = true; this.btnStartEnd.Click += new System.EventHandler(this.BtnStartEnd_Click); // - // btnAutomationBotConfig + // chkKeepToplevel // - this.btnAutomationBotConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnAutomationBotConfig.Location = new System.Drawing.Point(187, 3); - this.btnAutomationBotConfig.Name = "btnAutomationBotConfig"; - this.btnAutomationBotConfig.Size = new System.Drawing.Size(45, 23); - this.btnAutomationBotConfig.TabIndex = 6; - this.btnAutomationBotConfig.Text = "Cfg."; - this.btnAutomationBotConfig.UseVisualStyleBackColor = true; - this.btnAutomationBotConfig.Click += new System.EventHandler(this.btnAutomationBotConfig_Click); + this.chkKeepToplevel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkKeepToplevel.AutoSize = true; + this.chkKeepToplevel.Location = new System.Drawing.Point(15, 498); + this.chkKeepToplevel.Name = "chkKeepToplevel"; + this.chkKeepToplevel.Size = new System.Drawing.Size(117, 21); + this.chkKeepToplevel.TabIndex = 7; + this.chkKeepToplevel.Text = "KeepToplevel"; + this.chkKeepToplevel.UseVisualStyleBackColor = true; + this.chkKeepToplevel.CheckedChanged += new System.EventHandler(this.chkKeepToplevel_CheckedChanged); // // picPreview // @@ -175,10 +191,10 @@ | System.Windows.Forms.AnchorStyles.Right))); this.picPreview.BackColor = System.Drawing.Color.Black; this.picPreview.ImageShow = null; - this.picPreview.Location = new System.Drawing.Point(9, 10); - this.picPreview.Margin = new System.Windows.Forms.Padding(2); + this.picPreview.Location = new System.Drawing.Point(12, 12); + this.picPreview.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.picPreview.Name = "picPreview"; - this.picPreview.Size = new System.Drawing.Size(221, 217); + this.picPreview.Size = new System.Drawing.Size(218, 266); this.picPreview.TabIndex = 1; this.picPreview.TabStop = false; // @@ -187,19 +203,31 @@ this.ctrOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.ctrOutput.Location = new System.Drawing.Point(9, 64); - this.ctrOutput.Margin = new System.Windows.Forms.Padding(2); + this.ctrOutput.Location = new System.Drawing.Point(12, 79); + this.ctrOutput.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.ctrOutput.Name = "ctrOutput"; - this.ctrOutput.Size = new System.Drawing.Size(221, 356); + this.ctrOutput.Size = new System.Drawing.Size(218, 414); this.ctrOutput.TabIndex = 2; this.ctrOutput.Text = "ctrOutput1"; // + // chkClick + // + this.chkClick.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.chkClick.AutoSize = true; + this.chkClick.Location = new System.Drawing.Point(126, 53); + this.chkClick.Name = "chkClick"; + this.chkClick.Size = new System.Drawing.Size(39, 21); + this.chkClick.TabIndex = 8; + this.chkClick.Text = "C"; + this.chkClick.UseVisualStyleBackColor = true; + // // FrmScreenAutomation // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(566, 663); + this.ClientSize = new System.Drawing.Size(755, 816); this.Controls.Add(this.splitMain); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "FrmScreenAutomation"; this.Text = "ScreenAutomation"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmScreenAutomation_FormClosing); @@ -211,6 +239,7 @@ this.splitMain.ResumeLayout(false); this.splitOutput.Panel1.ResumeLayout(false); this.splitOutput.Panel2.ResumeLayout(false); + this.splitOutput.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitOutput)).EndInit(); this.splitOutput.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numFPS)).EndInit(); @@ -230,6 +259,8 @@ private System.Windows.Forms.ComboBox ddlAutomationBot; private System.Windows.Forms.NumericUpDown numFPS; private System.Windows.Forms.Button btnAutomationBotConfig; + private System.Windows.Forms.CheckBox chkKeepToplevel; + private System.Windows.Forms.CheckBox chkClick; } } diff --git a/VAR.ScreenAutomation/FrmScreenAutomation.cs b/VAR.ScreenAutomation/FrmScreenAutomation.cs index d02a71a..058a2c4 100644 --- a/VAR.ScreenAutomation/FrmScreenAutomation.cs +++ b/VAR.ScreenAutomation/FrmScreenAutomation.cs @@ -18,7 +18,7 @@ namespace VAR.ScreenAutomation public FrmScreenAutomation() { AutoScaleMode = AutoScaleMode.None; - AutoScaleDimensions = new SizeF(1, 1); + Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont); InitializeComponent(); } @@ -45,10 +45,12 @@ namespace VAR.ScreenAutomation { ddlAutomationBot.SelectedIndex = 0; } - InitBot((string)ddlAutomationBot.SelectedItem); numFPS.Value = configuration.Get("numFPS", (int)numFPS.Value); + chkKeepToplevel.Checked = configuration.Get("chkKeepToplevel", chkKeepToplevel.Checked); + chkClick.Checked = configuration.Get("chkClick", chkClick.Checked); + if (components == null) { components = new Container(); } timTicker = new Timer(components) { @@ -71,6 +73,8 @@ namespace VAR.ScreenAutomation configuration.Set("splitOutput.SplitterDistance", splitOutput.SplitterDistance); configuration.Set("ddlAutomationBot", (string)ddlAutomationBot.SelectedItem); configuration.Set("numFPS", (int)numFPS.Value); + configuration.Set("chkKeepToplevel", chkKeepToplevel.Checked); + configuration.Set("chkClick", chkClick.Checked); configuration.Save(); } @@ -117,7 +121,7 @@ namespace VAR.ScreenAutomation InitBot((string)ddlAutomationBot.SelectedItem); } - private void btnAutomationBotConfig_Click(object sender, EventArgs e) + private void BtnAutomationBotConfig_Click(object sender, EventArgs e) { if (_automationBot == null) { return; } IConfiguration defaultConfig = _automationBot.GetDefaultConfiguration(); @@ -135,12 +139,14 @@ namespace VAR.ScreenAutomation { if (_running) { return; } _running = true; - WindowHandling.WindowSetTopLevel(this); btnStartEnd.Text = "End"; InitBot((string)ddlAutomationBot.SelectedItem); - Point pointCapturerCenter = picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2)); - Mouse.SetPosition((uint)pointCapturerCenter.X, (uint)pointCapturerCenter.Y); - Mouse.Click(Mouse.MouseButtons.Left); + if (chkClick.Checked) + { + Point pointCapturerCenter = picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2)); + Mouse.SetPosition((uint)pointCapturerCenter.X, (uint)pointCapturerCenter.Y); + Mouse.Click(Mouse.MouseButtons.Left); + } } private void End() @@ -148,7 +154,6 @@ namespace VAR.ScreenAutomation if (_running == false) { return; } _running = false; btnStartEnd.Text = "Start"; - WindowHandling.WindowSetTopLevel(this, false); } private void InitBot(string botName) @@ -158,5 +163,28 @@ namespace VAR.ScreenAutomation botConfiguration.Load(); _automationBot?.Init(ctrOutput, botConfiguration); } + + private void chkKeepToplevel_CheckedChanged(object sender, EventArgs e) + { + WindowSetTopLevel(chkKeepToplevel.Checked); + } + + private bool _isToplevel = false; + + private void WindowSetTopLevel(bool toplevel) + { + if (toplevel) + { + if (_isToplevel) { return; } + WindowHandling.WindowSetTopLevel(this); + _isToplevel = true; + } + else + { + if (_isToplevel == false) { return; } + WindowHandling.WindowSetTopLevel(this, false); + _isToplevel = false; + } + } } }