문제

I want to make in my application, than when this application is in background, when I will click F10, the function with loop will be start.

This is my code:

    namespace test
    {
       public partial class Form1 : Form
       {
          [DllImport("user32.dll")]
          public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);

          [DllImport("user32.dll")]
          public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

          public Form1() //(lub Form1_Load(object sender, System.EventArgs e))
          {
             RegisterHotKey(this.Handle,9000, 2, (int) Keys.F10);   

             InitializeComponent();
          }

          private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
          {
             UnregisterHotKey(this.Handle,9000);
             UnregisterHotKey(this.Handle,9001);

          }

          protected override void WndProc(ref Message m)
          {
             base.WndProc(ref m);
             switch (m.Msg)
             {
               case 0x312:
                  switch (m.WParam.ToInt32())
                  {
                    case 9000:
                        //code
                        break;
                    case 9001:
                        //code
                        break;
                  }
                  break;
              }
          }
       }
    }

But don't work :(

Can you help me please?

도움이 되었습니까?

해결책

when I will click F10

Wrong key, you have to type Ctrl+F10. You passed 2 as the 3rd argument to RegisterHotKey(), that's MOD_CONTROL. Using const or enum declarations instead of raw literals help you fall in the pit of success.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top