Capturing the hot keys from a thread using c#;
<p>I am using the below code to capture the ctrl + alt + Q hot keys, which works perfectly.
But, i want to use this in a background application. Since my application does not have any forms, i want to use the same code inside a class file.</p>

<p>i am confuse, because i cannot write a event handler [keypressed] in class file.
Instead i want to use the keypress in thread.</p>

<p>Please help.</p>

<pre><code> public DialogResult Result; 
    KeyboardHook hook = new KeyboardHook();
    public Form1()
    {
        InitializeComponent();
        // register the event that is fired after the key press.
        hook.KeyPressed += new EventHandler&lt;KeyPressedEventArgs&gt;(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
        {

        }
    }
</code></pre>
