math-suite/Source/TibisMathematicsSuite/KeyboardIO/HotkeyWindow.cs

49 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TibisMathematicsSuite.KeyboardIO
{
class HotkeyWindow : NativeWindow, IDisposable
{
#region Constants
private const int WM_HOTKEY = 0x312;
#endregion
#region Events
public event EventHandler<MyKeyEventArgs> HotkeyPressed;
#endregion
#region Constructor
public HotkeyWindow()
{
this.CreateHandle(new System.Windows.Forms.CreateParams());
}
#endregion
#region Processor
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_HOTKEY && HotkeyPressed != null)
{
int vk = ((int)m.LParam >> 16) & 0xffff;
int mods = (int)m.LParam & 0xffff;
HotkeyPressed(this, new MyKeyEventArgs((Keys) vk, (MyKey.Modifiers) mods));
}
}
#endregion
#region Dispose
public void Dispose()
{
this.DestroyHandle();
}
#endregion
}
}