2012-04-02 40 views
0

我想在我的應用程序中製作,比當這個應用程序在後臺時,當我點擊F10時,循環的函數將被啓動。發送熱鍵在後臺編程

這是我的代碼:?

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; 
       } 
      } 
     } 
    } 

但不工作:(

你能幫我請

+1

請詳細說明什麼是不工作。 – cadrell0 2012-04-02 13:33:25

+0

這是去內功能WndProc,但從來沒有在9000和9001的情況下 – cadi2108 2012-04-02 13:51:45

+0

我不打算標記爲重複,但這可能是相關的? http://stackoverflow.com/questions/6664420/f10-key-is-not-caught – cadrell0 2012-04-02 14:21:24

回答

1

的時候我會點擊F10

錯誤的鍵,你必須鍵入Ctrl + F10。你作爲RegisterHotKey()的第三個參數傳遞了2,那就是MOD_控制。使用常量或枚舉聲明而不是原始文本可以幫助您陷入成功的困境。

+0

謝謝你,你是對的! – cadi2108 2012-04-03 08:57:49