请问除了Hook技术,还有没有别的方法模拟键鼠操作的? sendkey我曾经用这个发送键盘消息达到泡泡的自动回复功能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 模拟鼠标键盘要用hook?hook用来截取消息的比较多一些鼠标:mouse_event键盘:keydb_event 给你个简单的鼠标模拟参考参考using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Example107_模拟鼠标{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(144, 176); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "Mouse"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(280, 237); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.Name = "Form1"; this.Text = "Form1"; this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private System.Windows.Forms.Button button1; [System.Runtime.InteropServices.DllImport("user32")] private static extern int mouse_event(int dwFlags,int dx,int dy, int cButtons, int dwExtraInfo); const int MOUSEEVENTF_MOVE = 0x0001; const int MOUSEEVENTF_LEFTDOWN = 0x0002; const int MOUSEEVENTF_LEFTUP = 0x0004; const int MOUSEEVENTF_RIGHTDOWN = 0x0008; const int MOUSEEVENTF_RIGHTUP = 0x0010; const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; const int MOUSEEVENTF_MIDDLEUP = 0x0040; const int MOUSEEVENTF_ABSOLUTE = 0x8000; private void Form1_DoubleClick(object sender, System.EventArgs e) { MessageBox.Show("Double Click"); } private void button1_Click(object sender, System.EventArgs e) { mouse_event(MOUSEEVENTF_MOVE,-10,-10,0,0); mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); } }} 不用最低层的,其他的不知道啦。DirectX的话,找红星星!一个字----------求,也许他们帮你写一个。hohoho private void button1_Click(object sender, System.EventArgs e) { char strWindow; IntPtr hParent = IntPtr.Zero; IntPtr hNext=IntPtr.Zero; timer1.Enabled=false; string sClassName = "TestSendKey"; //要关闭的窗口标题 hNext=NativeWIN32.FindWindowEx(hParent,hNext,IntPtr.Zero,sClassName); if(hNext.ToInt32()>0) { NativeWIN32.SetForegroundWindow(hNext.ToInt32());//置顶显示 NativeWIN32.ShowWindow(hNext.ToInt32(),NativeWIN32.nCmdShow.SW_SHOWMINNOACTIVE); //显示窗口 System.Windows.Forms.SendKeys.Send("%{F4}");//要发送的值,这个是发 ALT+F4,具体其他的看帮助 } } } public class NativeWIN32 { [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern IntPtr FindWindowEx(IntPtr parent /*HWND*/, IntPtr next /*HWND*/, IntPtr sClassName, string sWindowTitle); [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern void SetForegroundWindow(int hwnd); [DllImport("user32.dll")] public static extern bool ShowWindow(int hWnd, nCmdShow nCmdShow); [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); //SendMessage(Handle2, WM_GETTEXT, 1024, Integer(@Buf)); public enum nCmdShow:uint { SW_FORCEMINIMIZE=0x0, SW_HIDE=0x1, SW_MAXIMIZE=0x2, SW_MINIMIZE=0x3, SW_RESTORE=0x4, SW_SHOW=0x5, SW_SHOWDEFAULT=0x6, SW_SHOWMAXIMIZED=0x7, SW_SHOWMINIMIZED=0x8, SW_SHOWMINNOACTIVE=0x9, SW_SHOWNA=0xA, SW_SHOWNOACTIVATE=0xB, SW_SHOWNORMAL=0xC, WM_CLOSE=0x10, } } 数据转换时,指定的转换无效。 Stream对象不能重复使用吗? c# 中DataGridView删除问题 为什么我的遨游(及360安全浏览器)验证码不刷新? 新手问几个简单的问题 datagrid上的datasource转换成datatable或者dataset C#关于排序的问题 求助~ 请问各位大虾,c#中如何获得文件路径 200分求打包时自动安装数据库. 初看C#问个简单的问题 请问在DataGrid里怎么样能改变超级链接列的样式啊?如链接的字体颜色。 下面的代码怎么解释
键盘:keydb_event
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Example107_模拟鼠标
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(144, 176);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Mouse";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 237);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private System.Windows.Forms.Button button1; [System.Runtime.InteropServices.DllImport("user32")]
private static extern int mouse_event(int dwFlags,int dx,int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000; private void Form1_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show("Double Click");
} private void button1_Click(object sender, System.EventArgs e)
{
mouse_event(MOUSEEVENTF_MOVE,-10,-10,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
}
}
{
char strWindow;
IntPtr hParent = IntPtr.Zero;
IntPtr hNext=IntPtr.Zero;
timer1.Enabled=false;
string sClassName = "TestSendKey"; //要关闭的窗口标题
hNext=NativeWIN32.FindWindowEx(hParent,hNext,IntPtr.Zero,sClassName);
if(hNext.ToInt32()>0)
{
NativeWIN32.SetForegroundWindow(hNext.ToInt32());//置顶显示
NativeWIN32.ShowWindow(hNext.ToInt32(),NativeWIN32.nCmdShow.SW_SHOWMINNOACTIVE); //显示窗口
System.Windows.Forms.SendKeys.Send("%{F4}");//要发送的值,这个是发 ALT+F4,具体其他的看帮助
}
}
}
public class NativeWIN32
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr parent /*HWND*/,
IntPtr next /*HWND*/,
IntPtr sClassName,
string sWindowTitle);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern void SetForegroundWindow(int hwnd); [DllImport("user32.dll")]
public static extern bool ShowWindow(int hWnd, nCmdShow nCmdShow); [DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); //SendMessage(Handle2, WM_GETTEXT, 1024, Integer(@Buf)); public enum nCmdShow:uint
{
SW_FORCEMINIMIZE=0x0,
SW_HIDE=0x1,
SW_MAXIMIZE=0x2,
SW_MINIMIZE=0x3,
SW_RESTORE=0x4,
SW_SHOW=0x5,
SW_SHOWDEFAULT=0x6,
SW_SHOWMAXIMIZED=0x7,
SW_SHOWMINIMIZED=0x8,
SW_SHOWMINNOACTIVE=0x9,
SW_SHOWNA=0xA,
SW_SHOWNOACTIVATE=0xB,
SW_SHOWNORMAL=0xC,
WM_CLOSE=0x10,
} }