winform注册系统快捷键

文章 精帖 2022-03-16 17:11 354 0 全屏看文

AI助手支持GPT4.0

using Microsoft.Win32;

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
	HotKey.UnregisterHotKey(Handle, 100);
}

class HotKey
{
	[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
	public static extern bool RegisterHotKey(IntPtr hWnd,int id, KeyModifiers fsModifiers,Keys vk);
	[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
	public static extern bool UnregisterHotKey(IntPtr hWnd,int id);
	[Flags()]
	public enum KeyModifiers
	{
		None = 0,
		Alt = 1,
		Ctrl = 2,
		Shift = 4,
		WindowsKey = 8
	}
}

protected override void WndProc(ref Message m)
{

	const int WM_HOTKEY = 0x0312;
	switch (m.Msg)
	{
		case WM_HOTKEY:
			switch (m.WParam.ToInt32())
			{
				case 160:
					JPbutton.PerformClick();
					break;
			}
			break;
	}
	base.WndProc(ref m);
}

private void MainForm_Load(object sender, EventArgs e)
{
	HotKey.RegisterHotKey(Handle, 160, HotKey.KeyModifiers.Alt, Keys.E);
}


-EOF-

AI助手支持GPT4.0


您还可能感兴趣的文章