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