- [C#] Di chuyển và thay đổi kích thước Control Winform khi ứng dụng đang chạy
- [VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng
- [C#] Hướng dẫn chỉnh sửa Text của label trực tiếp trên winform
- [C#] Hướng dẫn custom TextBox giống Ultraviewer trên Winform
- [C#] Show Modal Winform like Bootstrap
- [DATABASE] Thứ tự thực hiện mệnh đề truy vấn SELECT trong Sqlserver
- [C#] Hướng dẫn viết addin Excel Lấy hình ảnh từ URL internet vào Excel
- [DATABASE] TSQL view max length all column data trên table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng MailMerge kèm Hình ảnh trên Winform
- [DATABASE] Hướng dẫn truy vấn xem kích thước lưu trữ của từng bảng ghi Table trên sqlserver
- [C#] Hướng dẫn Fake Date Time sử dụng thư viện Harmony
- [DATABASE] Phân biệt câu lệnh DDL và DML trong sqlserver
- [C#] Hướng dẫn convert file mã HTML sang file Pdf trên winform
- [DEVEXPRESS] Tạo các loại mã vạch Barcode trực tiếp trên Devexpress Barcode API
- [DEVEXPRESS] Hướng dẫn custom Simple button thành Progressbar
- [DATABASE] Tách số và chữ từ chuỗi - hàm tối ưu hóa tách số và chữ trong Sqlserver
- [C#] Tìm kiếm gần đúng Full Text Search sử dụng thư viện Lucene.NET
- [C#] Chia sẻ tài liệu, sdk và source code máy chấm công dòng máy ZKTeco
- [C#] Memory Cache là gì, và sử dụng trong ứng dụng Winform
- [DATABASE] Khóa chính Primary Key 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!