c# - 如何添加多个热键?像 f1 f2 f3
问题描述
我不明白: Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
KeyModifier 修饰符 = (KeyModifier)((int)m.LParam & 0xFFFF);
在此代码中只添加一个热键,我如何添加多个热键?喜欢f1 f2 f3。。。。</p>
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
enum KeyModifier
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
WinKey = 8
}
public Form1()
{
InitializeComponent();
int id = 0;
RegisterHotKey(this.Handle, id, 0, Keys.F2.GetHashCode());
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
int id = m.WParam.ToInt32();
MessageBox.Show("Hotkey has been pressed!");
}
}
解决方案
推荐阅读
- r - 合并不同行的日期和时间
- r - 控制 ggplot2 中离散比例的相对大小
- odoo - Odoo 添加自定义日志处理程序
- android - 为什么 android studio 总是安装 sdk 平台 26
- javascript - 升级到 React v16,看到 Error: parentComponent must be a valid React Component
- reactjs - 在新页面中显示嵌套路由组件
- rest - REST:返回“A”类型对象的两个 REST 请求的响应的单一表示
- android - Android 设备未连接
- android - 将 RealmList 与 Moshi 一起使用时出错
- android - 如何使用 Android_ID 与其他设备通信?