C#如何实现热键??

来源:百度知道 编辑:UC知道 时间:2024/06/04 09:47:37
比如按F1后,,启动timer1...要怎么写??

//
[DllImport("user32.dll")]
public static extern UInt32 RegisterHotKey( IntPtr hWnd, UInt32 id, UInt32 fsModifiers, UInt32 vk);

//注册热键
RegisterHotKey(this.Handle, 0x3400, 1, (UInt32)Keys.Z);

//
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;

Console.WriteLine(m.Msg.ToString("X"));

switch(m.Msg)
{
case WM_HOTKEY:
if (m.WParam.ToInt32() == 0x3400)
{
//添加你自己的代码
Console.WriteLine("Start ...");
}
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}