这是一个可以在Form 或者UserControl 中自定义Ctrl ,Shift + 非系统按键组成热键,并截获热键消息处理的class,可是一直没有找到好办法实现Alt键作为单一辅助键实现如Alt+F1 的热键,望高手指点。
using System;
using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;
namespace HotKey
{
public enum KeyModifiers
{
Ctrl = Keys.Control,
Shift = Keys.Shift
}
public struct HotkeyDefine
{
private KeyModifiers[] kms;
private Keys key;
private HotKeyHandler hh;
public HotKeyHandler Hh
{
get
{
return this.hh;
}
}
public KeyModifiers[] Kms
{
get
{
return this.kms;
}
}
public Keys Key
{
get
{
return this.key;
}
}
public HotkeyDefine(KeyModifiers[] kms, Keys key, HotKeyHandler hh)
{
this.kms = kms;
this.key = key;
this.hh = hh;
}
}
public class HotkeyEventArgs : EventArgs
{
public HotkeyEventArgs(bool CtrlPressed,bool ShiftPressed,Keys key)
{
this.ctrlPressed = CtrlPressed;
this.shiftPressed = ShiftPressed;
this.key = key;
}
private bool ctrlPressed;
private bool shiftPressed;
private Keys key;
public bool CtrlPressed
{
get
{
return this.ctrlPressed;
}
}
public bool ShiftPressed
{
get