- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
- [C#] Hướng dẫn tạo ứng dụng dock windows giống Taskbar
- [C#] Chia sẻ source code sử dụng Object Listview trên Winform
- [VB.NET] Chia sẻ source code quản lý thu chi mô hình 3 lớp Winform
- [DATABASE] Xóa lịch sử danh sách đăng nhập tài khoản trên SMSS Sqlserver Management Studio
- [C#] Sử dụng FolderBrowserDialog Vista trên Winform
- [DEVEXPRESS] Chia sẻ tool Winform UI Templates Early Access Preview (EAP)
- [C#] Chia sẻ source code Spin Content (Trộn nội dung văn bản theo từ đồng nghĩa) trên Winform
- [VB.NET] Chia sẻ source code lịch âm dương và hẹn lịch nhắc việc
- [C#] Hướng dẫn đọc thông số thiết bị Thiết bị kiểm tra Pin (HIOKI BATTERY HiTESTER BT3562)
- [VB.NET] Hướng dẫn giải captcha sử dụng dịch vụ AZCaptcha API trên winform
- [C#] Hướng dẫn chứng thực đăng nhập ứng dụng bằng vân tay (Finger Print) trên máy tính
- [C#] Color Thief cách xuất màu sắc thiết kế từ hình ảnh
- [C#] Cách tạo bản quyền và cho phép dùng thử ứng dụng Winform
- [C#] Hướng dẫn sử dụng trình duyệt web Chrome convert HTML sang tập tin file PDF
- [C#] Kết nôi điện thoại Android, IOS với App Winform via Bluetooth
- [DATABASE] Cách query cộng trừ dồn dần trong Sqlserver
[C#] Hướng dẫn viết app Auto Typer từ clipboard
Xin chào các bạn, bài viết hôm nay mình tiếp tục các bạn cách viết ứng dụng Auto Typer từ Copied Clipboard trong lập trình C#, Winform.
[C#] Auto Typer From Copied Clipboard - SendKeys
Dưới đây, là giao diện demo ứng dụng:
Ở đây, các bạn có thể chỉnh tốc độ để write text từ clipboard
Các bạn copy text xong chọn editor hay bất cứ chỗ nào cần send text, rồi bấm phím F1
để bắt đầu.
Các bạn có thể xem video demo Auto Typer C#:
Source code C#:
using System;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using WindowsInput;
using WindowsInput.Native;
namespace AutoTyper
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
int speed = 10;
enum KeyModifier
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
WinKey = 8
}
public Form1()
{
InitializeComponent();
// int id = 0;
RegisterHotKey(this.Handle, 0, (int)KeyModifier.None, Keys.F1.GetHashCode());
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
int id = m.WParam.ToInt32();
TyperingText();
}
}
public void TyperingText()
{
var dataText = Clipboard.GetText();
var resultString = Regex.Replace(dataText, @"^\s+$[\r\n]*", string.Empty, RegexOptions.Multiline);
simulateTypingText(resultString, typingDelay: speed);
}
private void simulateTypingText(string Text, int typingDelay = 100, int startDelay = 0)
{
InputSimulator sim = new InputSimulator();
sim.Keyboard.Sleep(1000);
sim.Keyboard.Sleep(startDelay);
string[] lines = Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
int maximum = lines.Length;
int current = 1;
foreach (string line in lines)
{
char[] words = line.ToCharArray();
foreach (char word in words)
{
sim.Keyboard.TextEntry(word).Sleep(typingDelay);
}
float percentage = ((float)current / (float)maximum) * 100;
current++;
sim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
sim.Keyboard.KeyPress(VirtualKeyCode.HOME);
Console.WriteLine("Percent : {0}", percentage.ToString());
}
}
private void txtSpeed_TextChanged(object sender, EventArgs e)
{
speed = Convert.ToInt32(txtSpeed.Text);
}
}
}
Thanks for watching!