2009-12-08 29 views
0

我希望我的應用程序能夠在未檢測到用戶輸入一段時間(如歡迎/指令層)時顯示某些信息。無論如何要讓應用程序註冊任何形式的用戶輸入(鍵盤,mousedown/move等),而無需爲每個事件編寫處理程序?是否有可能在C#中捕獲任何非特定的輸入事件?

是否有一個通用的輸入窗口消息在被解釋爲鼠標或鍵盤或其他設備之前被髮送?我想要的行爲類似於Windows從鍵盤或鼠標輸入的屏幕保護程序/睡眠喚醒。

我想避免類似:

void SomeHandler(object sender, EventArgs e) { WakeUp(); } 
... 
this.KeyDown += SomeHandler; 
this.MouseMove += SomeHandler; 
this.SomeInputInteraction += SomeHandler; 

回答

2

GetLastInputInfo Function也可能是你在找什麼。它檢索最後輸入事件的時間。

+0

謝謝,其實這就是我以後 – jeffora 2009-12-08 00:31:33

0

也許這篇文章對CodeProjecthelp你。這是關於使用WPF一段時間不活動後自動註銷。

希望這會有所幫助。

+0

感謝我,有趣的閱​​讀和有用的信息 - 比我更詳細的方法比之後 – jeffora 2009-12-08 00:32:12

0

我不知道,如果這個工程在WPF,但是這可能會幫助:

public class DetectInput : IMessageFilter 
{ 
    public bool PreFilterMessage(ref Message m) 
    { 

     if ( m.Msg == (int)WindowsMessages.WM_KEYDOWN 
      || m.Msg == (int)WindowsMessages.WM_MOUSEDOWN 
      // add more input types if you want 
      ) 
     { 
      // Do your stuff here 
     } 

     return false; 
    } 
} 

和程序:

Application.AddMessageFilter(new DetectInput()); // Must come before Run 
Application.Run(YourForm); 
相關問題