关于C#在WIN8的模拟按键,求教
1个回答
展开全部
注册全局热键及代码控件键盘输入按键
private void btnStart_Click(object sender, EventArgs e)
{
RegisterHotKey(this.Handle, 469487202, 0, (UInt32)Keys.F2);//注册热键F2
RegisterHotKey(this.Handle, 469487203, 0, (UInt32)Keys.F3);//注册热键F3
}
private void btnStop_Click(object sender, EventArgs e)
{
UnregisterHotKey(this.Handle, 469487202);//移除热键F2
UnregisterHotKey(this.Handle, 469487203);//移除热键F3
}
//重写消息循环
protected override void WndProc(ref Message m)
{
if (m.WParam.ToInt32() == 469487202)//F2
{
Thread.Sleep(300);
SendKeys.SendWait("{2}");
Thread.Sleep(300);
SendKeys.SendWait("{2}");
}
else if (m.WParam.ToInt32() == 469487203)//F3
{
Thread.Sleep(300);
SendKeys.SendWait("{3}");
Thread.Sleep(300);
SendKeys.SendWait("{3}");
}
base.WndProc(ref m);
}
[DllImport("user32.dll")]
public static extern UInt32 RegisterHotKey(IntPtr hWnd, UInt32 id, UInt32 fsModifiers, UInt32 vk); //API
[DllImport("user32.dll")]
public static extern UInt32 UnregisterHotKey(IntPtr hWnd, UInt32 id);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询