0
我使用下面的代碼來捕獲完美的ctrl + alt + Q熱鍵。 但是,我想在後臺應用程序中使用它。由於我的應用程序沒有任何形式,我想在類文件中使用相同的代碼。使用c#從線程捕獲熱鍵;
我很困惑,因爲我無法在類文件中寫入事件處理函數[keypressed]。 相反,我想在線程中使用按鍵。
請幫忙。
public DialogResult Result;
KeyboardHook hook = new KeyboardHook();
public Form1()
{
InitializeComponent();
// register the event that is fired after the key press.
hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(hook_KeyPressed);
// register the control + alt + F12 combination as hot key.
hook.RegisterHotKey((ModifierKeys)2 | (ModifierKeys)1, Keys.Q);
}
void hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
Result = MessageBox.Show("Are you sure, you want to log off?","Log off"
,MessageBoxButtons.YesNo
,MessageBoxIcon.Warning);
if (Result == DialogResult.Yes)
{
}
else
{
}
}
好吧然後,我會做一個使用表格。但是有沒有辦法讓表單看不見,它甚至不會在任務欄中出現。 可能嗎?謝謝。 – Anuya 2009-07-15 05:35:10