예제 #1
0
 //private Window window;
 //stack overflow http://stackoverflow.com/questions/2450373/set-global-hotkeys-using-c-sharp
 //private class Window : NativeWindow, IDisposable
 //{
 //    private static int WM_HOTKEY = 0x0312;
 //    private IHotKeyOwner owner;
 //    public Window(IHotKeyOwner owner)
 //    {
 //        this.owner = owner;
 //        // create the handle for the window.
 //        this.CreateHandle(new CreateParams());
 //    }
 //    /// <summary>
 //    /// Overridden to get the notifications.
 //    /// </summary>
 //    /// <param name="m"></param>
 //    protected override void WndProc(ref Message m)
 //    {
 //        base.WndProc(ref m);
 //        // check if we got a hot key pressed.
 //        if (m.Msg == WM_HOTKEY)
 //        {
 //            MessageBox.Show("asdasd");
 //            // get the keys.
 //            Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
 //            ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
 //            owner.HotKeyPressed(0);
 //        }
 //    }
 //    #region IDisposable Members
 //    public void Dispose()
 //    {
 //        this.DestroyHandle();
 //    }
 //    #endregion
 //}
 public HotKeyManager(IHotKeyOwner owner, IntPtr handle)
 {
     this.owner = owner;
     this.hook = new HwndSourceHook(WndProc);
     this.hwndsource = HwndSource.FromHwnd(handle);
     hwndsource.AddHook(hook);
 }