焦点丢失时处理打印屏幕

时间:2010-09-01 17:19:48

标签: c# wpf

我在表单上有一个文本框,每次使用alt和打印屏幕键时都会递增 按下,特别是打印屏幕键的上方。一切正常。但是什么 我需要完成的是即使焦点发生变化也能保持这种状态。下面 是我的代码到目前为止:我被告知要为此创建一个钩子,因为它在我的应用程序之外,所以对此的任何帮助将不胜感激...谢谢

public Form2()
{
    InitializeComponent();
    this.KeyUp += new KeyEventHandler(Form2_KeyUp);
}

public void Form2_KeyUp(object sender, KeyEventArgs e)
{
    //If the Alt key was pressed and the PrintScreen key was the one released, bump                        
    //the counter and update the textbox.

    if (e.Alt && (e.KeyCode == Keys.PrintScreen))
        count++;
        try
        {
            if (count == 0)
                textBox1.Text = "0";
            else
            {
                textBox1.Text = ("" + count);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        finally
        {

        }
    }
}

1 个答案:

答案 0 :(得分:2)

看看this article。它告诉您如何注册Windows挂钩,例如,它特别提到了键盘事件。

相关问题