문제

I have one class to register/unregister hotkey. It works perfectly when application start with Form Load event.

private Hotkey myHotKey;
private IntPtr thisWindow;
    private void Form1_Load(object sender, EventArgs e)
      {
          thisWindow = FindWindow(null, "Form1");
          myHotKey = new Hotkey(thisWindow);
          myHotKey.RegisterHotKeys();

      }

Now problem is I want to hide application in system tray at start but its not registering my host key , When I run below code it is displaying me successfully Notify() and other things except my hotkey have no effect.:

public Form1()
{
    InitializeComponent();
    notifyIcon1.ContextMenuStrip = contextMenuStrip1;
    notifyIcon1.Click += notifyIcon1_Click;
    notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
    openToolStripMenuItem.Click += openToolStripMenuItem_Click;
    exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
    Notify("Application Name", "Application Started...", 1000);
    thisWindow = FindWindow(null, "Form1");
    myHotKey = new Hotkey(thisWindow);
    myHotKey.RegisterHotKeys();
}

Can you please guide me what I am doing wrong. Thank you

도움이 되었습니까?

해결책

Thanks guys for help, I came across this example which explained everything in better way:

http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html

hotkey = new GlobalHotkeys();
hotkey.RegisterGlobalHotKey( (int) Keys.F11, GlobalHotkeys.MOD_CONTROL, this.Handle);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top