Click vào tọa độ không chiếm chuột trong điều khiển ứng dụng PC

auto click khong chiem chuot

Dẫn nhập

Chào các bạn! Trong các khóa học trước của chuỗi khóa học Auto C# chúng ta đã cùng tìm hiểu về SELENIUM và HTTP REQUEST trong C#.

Ở khóa học này, bạn sẽ được tìm hiểu thêm một phần khá thú vị, đó là LẬP TRÌNH ĐIỀU KHIỂN ỨNG DỤNG PC VỚI C#. Mục đích hướng tới là các bạn có thể làm auto bằng C# mà không cần dùng tới các ngôn ngữ như AutoIT, C++,…

Chúng ta đã biết cách CLICK VÀO CONTROL KHÔNG CHIẾM CHUỘT , tiếp theo chúng ta sẽ cùng tìm hiểu về cách Click vào tọa độ không chiếm chuột trong điều khiển ứng dụng PC

Nội dung

Nội dung bao gồm Source code & các lưu ý chính về quá trình thực hiện phần mềm. Kteam khuyến khích bạn cập nhập thêm nhiều kinh nghiệm cũng như hiểu chi tiết hơn về các kỹ thuật được đề cập trong bài học thông qua các video đính kèm.

Đừng quên Like Facebook hoặc +1 Google để ủng hộ Kteam và tác giả.

Để có đủ khả năng học hiểu các nội dung được đề cập đến trong khóa học. Bạn nên có tối thiểu kiến thức về các phần:

  • LẬP TRÌNH C# CƠ BẢN
  • LẬP TRÌNH KEYLOGGER
  • LẬP TRÌNH C# WINFORM

Ngoài ra, cũng nên trau dồi thêm kiến thức khác qua các project thực tế như:

  • LẬP TRÌNH TỪ ĐIỂN NÓI VỚI C# WINFORM
  • LẬP TRÌNH GAME CARO VỚI C# WINFORM
  • LẬP TRÌNH ỨNG DỤNG LẬP LỊCH VỚI C# WINFORM

Phần mềm sử dụng

Để việc thao tác theo hướng dẫn được tốt nhất bạn nên cài đặt phần mềm

  • Visual Sutdio mới nhất (2015 hoặc 2017 community)

Project tham khảo

Form1.cs

using KAutoHelper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AutoControlAppPC { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Process.Start(“notepad”); } private void button2_Click(object sender, EventArgs e) { //Process.Start(AppDomain.CurrentDomain.BaseDirectory + “How Kteam – Free Education.html”); Process.Start(“How Kteam – Free Education.html”); } private void button3_Click(object sender, EventArgs e) { string strCmdText; strCmdText = “/C ping -t howkteam.com”; Process.Start(“CMD.exe”, strCmdText); } private void button4_Click(object sender, EventArgs e) { string strCmdText; strCmdText = @”/C “”How Kteam – Free Education.html”””; Process p = new Process(); p.StartInfo.FileName = “CMD.exe”; p.StartInfo.Arguments = strCmdText; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); //p.Kill(); /* System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = “cmd.exe”; startInfo.Arguments = @”/C “”How Kteam – Free Education.html”””; process.StartInfo = startInfo; process.Start(); */ } private void button5_Click(object sender, EventArgs e) { string cmdCommand = “ping howkteam.com”; Process cmd = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = “cmd.exe”; startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; cmd.StartInfo = startInfo; cmd.Start(); cmd.StandardInput.WriteLine(cmdCommand); cmd.StandardInput.Flush(); cmd.StandardInput.Close(); cmd.WaitForExit(); string result = cmd.StandardOutput.ReadToEnd(); MessageBox.Show(result); } private void button6_Click(object sender, EventArgs e) { int x = (int)numericUpDown1.Value; int y = (int)numericUpDown2.Value; EMouseKey mouseKey = EMouseKey.LEFT; if (checkBox1.Checked) { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_RIGHT; } else { mouseKey = EMouseKey.RIGHT; } } else { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_LEFT; } } //Cursor.Position = new Point(x,y); AutoControl.MouseClick(x,y, mouseKey); } private void button7_Click(object sender, EventArgs e) { int x = (int)numericUpDown1.Value; int y = (int)numericUpDown2.Value; //var hWnd = Process.GetProcessById(12012).MainWindowHandle; //var hWnd = Process.GetProcessesByName(“Remote Desktop Connection”)[0].MainWindowHandle; IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); // lấy ra tọa độ trên màn hình của tọa độ bên trong cửa sổ var pointToClick = AutoControl.GetGlobalPoint(hWnd, x,y); EMouseKey mouseKey = EMouseKey.LEFT; if (checkBox1.Checked) { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_RIGHT; } else { mouseKey = EMouseKey.RIGHT; } } else { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_LEFT; } } AutoControl.BringToFront(hWnd); AutoControl.MouseClick(pointToClick, mouseKey); } private void button8_Click(object sender, EventArgs e) { int x = (int)numericUpDown1.Value; int y = (int)numericUpDown2.Value; IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); var childhWnd = IntPtr.Zero; // Tìm ra handle con mà thỏa điều kiện text và class y chang //childhWnd = AutoControl.FindWindowExFromParent(hWnd, null, textBox2.Text); //Tìm ra handle con mà thỏa text hoặc class giống childhWnd = AutoControl.FindHandle(hWnd, textBox2.Text, textBox2.Text); // lấy ra tọa độ trên màn hình của tọa độ bên trong cửa sổ var pointToClick = AutoControl.GetGlobalPoint(childhWnd, x, y); EMouseKey mouseKey = EMouseKey.LEFT; if (checkBox1.Checked) { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_RIGHT; } else { mouseKey = EMouseKey.RIGHT; } } else { if (checkBox2.Checked) { mouseKey = EMouseKey.DOUBLE_LEFT; } } AutoControl.BringToFront(hWnd); AutoControl.MouseClick(pointToClick, mouseKey); } private void button9_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); AutoControl.BringToFront(hWnd); AutoControl.SendKeyFocus(KeyCode.ENTER); } private void button10_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); AutoControl.BringToFront(hWnd); AutoControl.SendMultiKeysFocus(new KeyCode[] { KeyCode.CONTROL, KeyCode.KEY_V}); } private void button11_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); AutoControl.SendText(hWnd, “howkteam.com”); } private void button12_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); //Tìm ra handle con mà thỏa text hoặc class giống var childhWnd = AutoControl.FindHandle(hWnd, “ComboBoxEx32”, null); AutoControl.SendText(childhWnd, “howkteam.com”); } private void button13_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); var childhWnd = AutoControl.FindHandle(hWnd, textBox2.Text, textBox2.Text); AutoControl.SendClickOnControlByHandle(childhWnd); } private void button14_Click(object sender, EventArgs e) { IntPtr hWnd = IntPtr.Zero; hWnd = AutoControl.FindWindowHandle(null, textBox1.Text); var childhWnd = AutoControl.FindHandle(hWnd, textBox2.Text, textBox2.Text); int x = (int)numericUpDown1.Value; int y = (int)numericUpDown2.Value; // Phải click vào handle con. Không thể click vào handle window // Không phải ứng dụng nào cũng click được. AutoControl.SendClickOnPosition(childhWnd, x,y); } } }

Form1.Designer.cs

namespace AutoControlAppPC { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name=”disposing”>true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support – do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.button7 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button8 = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.button9 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.button11 = new System.Windows.Forms.Button(); this.button12 = new System.Windows.Forms.Button(); this.button13 = new System.Windows.Forms.Button(); this.button14 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = “button1”; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = “Mở notepad”; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(93, 12); this.button2.Name = “button2”; this.button2.Size = new System.Drawing.Size(112, 23); this.button2.TabIndex = 1; this.button2.Text = “Mở file/Ứng dụng”; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.Location = new System.Drawing.Point(12, 41); this.button3.Name = “button3”; this.button3.Size = new System.Drawing.Size(122, 23); this.button3.TabIndex = 2; this.button3.Text = “Chạy lệnh CMD”; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Location = new System.Drawing.Point(140, 41); this.button4.Name = “button4”; this.button4.Size = new System.Drawing.Size(122, 23); this.button4.TabIndex = 3; this.button4.Text = “Chạy lệnh CMD ngầm”; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button5 // this.button5.Location = new System.Drawing.Point(268, 41); this.button5.Name = “button5”; this.button5.Size = new System.Drawing.Size(203, 23); this.button5.TabIndex = 4; this.button5.Text = “Chạy lệnh CMD ngầm và lấy kết quả”; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button6 // this.button6.Location = new System.Drawing.Point(373, 67); this.button6.Name = “button6”; this.button6.Size = new System.Drawing.Size(149, 23); this.button6.TabIndex = 5; this.button6.Text = “Click vào tọa độ màn hình”; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(12, 70); this.numericUpDown1.Maximum = new decimal(new int[] { 3000, 0, 0, 0}); this.numericUpDown1.Minimum = new decimal(new int[] { 3000, 0, 0, -2147483648}); this.numericUpDown1.Name = “numericUpDown1”; this.numericUpDown1.Size = new System.Drawing.Size(75, 20); this.numericUpDown1.TabIndex = 6; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(93, 70); this.numericUpDown2.Maximum = new decimal(new int[] { 3000, 0, 0, 0}); this.numericUpDown2.Minimum = new decimal(new int[] { 3000, 0, 0, -2147483648}); this.numericUpDown2.Name = “numericUpDown2”; this.numericUpDown2.Size = new System.Drawing.Size(75, 20); this.numericUpDown2.TabIndex = 7; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(174, 73); this.checkBox1.Name = “checkBox1”; this.checkBox1.Size = new System.Drawing.Size(77, 17); this.checkBox1.TabIndex = 8; this.checkBox1.Text = “Chuột phải”; this.checkBox1.UseVisualStyleBackColor = true; // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(257, 73); this.checkBox2.Name = “checkBox2”; this.checkBox2.Size = new System.Drawing.Size(85, 17); this.checkBox2.TabIndex = 9; this.checkBox2.Text = “Double click”; this.checkBox2.UseVisualStyleBackColor = true; // // button7 // this.button7.Location = new System.Drawing.Point(528, 67); this.button7.Name = “button7”; this.button7.Size = new System.Drawing.Size(149, 23); this.button7.TabIndex = 10; this.button7.Text = “Click vào tọa độ ứng dụng”; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(683, 69); this.textBox1.Name = “textBox1”; this.textBox1.Size = new System.Drawing.Size(153, 20); this.textBox1.TabIndex = 11; this.textBox1.Text = “Remote Desktop Connection”; // // button8 // this.button8.Location = new System.Drawing.Point(12, 96); this.button8.Name = “button8”; this.button8.Size = new System.Drawing.Size(149, 23); this.button8.TabIndex = 12; this.button8.Text = “Click vào control ứng dụng”; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // textBox2 // this.textBox2.Location = new System.Drawing.Point(167, 98); this.textBox2.Name = “textBox2”; this.textBox2.Size = new System.Drawing.Size(153, 20); this.textBox2.TabIndex = 13; this.textBox2.Text = “ToolbarWindow32”; // // button9 // this.button9.Location = new System.Drawing.Point(12, 125); this.button9.Name = “button9”; this.button9.Size = new System.Drawing.Size(149, 23); this.button9.TabIndex = 14; this.button9.Text = “Gửi phím cho ứng dụng”; this.button9.UseVisualStyleBackColor = true; this.button9.Click += new System.EventHandler(this.button9_Click); // // button10 // this.button10.Location = new System.Drawing.Point(167, 124); this.button10.Name = “button10”; this.button10.Size = new System.Drawing.Size(149, 23); this.button10.TabIndex = 15; this.button10.Text = “Gửi tổ hợp phím cho ứng dụng”; this.button10.UseVisualStyleBackColor = true; this.button10.Click += new System.EventHandler(this.button10_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(12, 190); this.label1.Name = “label1”; this.label1.Size = new System.Drawing.Size(162, 13); this.label1.TabIndex = 16; this.label1.Text = “Không chiếm chuột và bàn phím”; // // button11 // this.button11.Location = new System.Drawing.Point(15, 221); this.button11.Name = “button11”; this.button11.Size = new System.Drawing.Size(149, 23); this.button11.TabIndex = 17; this.button11.Text = “Sửa tiêu đề của cửa sổ”; this.button11.UseVisualStyleBackColor = true; this.button11.Click += new System.EventHandler(this.button11_Click); // // button12 // this.button12.Location = new System.Drawing.Point(174, 221); this.button12.Name = “button12”; this.button12.Size = new System.Drawing.Size(149, 23); this.button12.TabIndex = 18; this.button12.Text = “Gửi text cho combobox”; this.button12.UseVisualStyleBackColor = true; this.button12.Click += new System.EventHandler(this.button12_Click); // // button13 // this.button13.Location = new System.Drawing.Point(15, 250); this.button13.Name = “button13”; this.button13.Size = new System.Drawing.Size(149, 23); this.button13.TabIndex = 19; this.button13.Text = “Click vào control của ứng dụng”; this.button13.UseVisualStyleBackColor = true; this.button13.Click += new System.EventHandler(this.button13_Click); // // button14 // this.button14.Location = new System.Drawing.Point(15, 279); this.button14.Name = “button14”; this.button14.Size = new System.Drawing.Size(149, 23); this.button14.TabIndex = 20; this.button14.Text = “Click vào tọa độ ngầm”; this.button14.UseVisualStyleBackColor = true; this.button14.Click += new System.EventHandler(this.button14_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(848, 350); this.Controls.Add(this.button14); this.Controls.Add(this.button13); this.Controls.Add(this.button12); this.Controls.Add(this.button11); this.Controls.Add(this.label1); this.Controls.Add(this.button10); this.Controls.Add(this.button9); this.Controls.Add(this.textBox2); this.Controls.Add(this.button8); this.Controls.Add(this.textBox1); this.Controls.Add(this.button7); this.Controls.Add(this.checkBox2); this.Controls.Add(this.checkBox1); this.Controls.Add(this.numericUpDown2); this.Controls.Add(this.numericUpDown1); this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = “Form1”; this.Text = “Form1”; ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.NumericUpDown numericUpDown2; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.Button button7; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button8; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button9; private System.Windows.Forms.Button button10; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button11; private System.Windows.Forms.Button button12; private System.Windows.Forms.Button button13; private System.Windows.Forms.Button button14; } }

Xem thêm:  Sony E6683 – Chiếc điện thoại thông minh chất lượng cao của Sony

Project tải xuống

Nếu việc thực hành theo hướng dẫn không diễn ra suôn sẻ như mong muốn. Bạn cũng có thể tải xuống PROJECT THAM KHẢO ở link bên dưới!

Phần mềm & Thư viện khác

uc?id=1QlpuQRAVeEUsqymWlqz3CL 7HQ 7gDY3

Kết

Trong bài này, chúng ta đã tìm hiểu cách Click vào tọa độ không chiếm chuột trong điều khiển ứng dụng PC.

Ở bài sau, Kteam sẽ giới thiệu đến bạn cách GỬI PHÍM NGẦM TRONG ĐIỀU KHIỂN ỨNG DỤNG PC

Cảm ơn các bạn đã theo dõi bài viết. Hãy để lại bình luận hoặc góp ý của mình để phát triển bài viết tốt hơn. Và đừng quên “Luyện tập – Thử Thách – Không ngại khó

Thảo luận

Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần BÌNH LUẬN bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.