RegisterHotKey注册快捷键为什么F12不好使?
F11及其他是好使的,可是我偏偏想要使用F12!!郁闷 代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/// <summary>
///这个函数用于注册热键
/// </summary>
/// <param name="hWnd">要定义热键的窗口的句柄</param>
/// <param name="id">定义热键ID(不能与其它ID重复)</param>
/// <param name="fsModifiers">标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效</param>
/// <param name="vk">定义热键的内容</param>
/// <returns></returns>
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(
IntPtr hWnd, //要定义热键的窗口的句柄
int id, //定义热键ID(不能与其它ID重复)
KeyModifiers fsModifiers, //标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效
Keys vk //定义热键的内容
);
//定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值)
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Ctrl = 2,
Shift = 4,
WindowsKey = 8
}
private void Form2_Load(object sender, EventArgs e)
{
RegisterHotKey(Handle, 100, KeyModifiers.None, Keys.F11);
RegisterHotKey(Handle, 101, KeyModifiers.None, Keys.F12);
}
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
//按快捷键
switch (m.Msg)
{
case WM_HOTKEY:
switch (m.WParam.ToInt32())
{
case 100: //按下的是F11
MessageBox.Show("F11");
break;
case 101: //按下的是F12
MessageBox.Show("F12");
break;
}
break;
}
base.WndProc(ref m);
}
}
}
我是半路出家,而且是自学 学的是C#语言,希望回帖的高手们留意一下,谢谢大家的帮助