Chào các bạn. Dạo này box này đang hot. Mình xin góp vui bằng ứng dụng send key đơn giản viết bằng C#. Do khả năng và thời gian có hạn nên chương trình còn thiếu tính năng như bẫy lỗi, tìm cửa sổ theo title (chương trình đang tìm bằng class name), hiển thị title của các cửa sổ để dễ chọn lựa. Các bạn nhập class name vào textbox, bấm Find windows, các cửa sổ tìm được sẽ được load vào combobox, chọn 1 cửa sổ, nhập keys rồi bấm Send.
C#:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace SendKeyToAnotheApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr point);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32")]
public static extern int UpdateWindow(IntPtr hwnd);
private void btnSend_Click(object sender, EventArgs e)
{
IntPtr hWnd = (IntPtr)Int64.Parse(comboBox1.Text);
TopMost = true;
ShowWindow(hWnd, 9);
SetForegroundWindow(hWnd);
SendKeys.Send(txtStringToBeSend.Text);
TopMost = false;
UpdateWindow(hWnd);
}
private void btnFind_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
foreach (Process p in Process.GetProcessesByName(txtName.Text)){
comboBox1.Items.Add(p.MainWindowHandle);
}
comboBox1.Text = comboBox1.Items[0].ToString();
}
}
}
Bạn cần đăng nhập để thấy đính kèm
Bạn cần đăng nhập để thấy link
Sửa lần cuối: