- [DEVEXPRESS] Chia sẻ code các tạo report in nhiều hóa đơn trên XtraReport C#
- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
[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!