Capturing the windows key in c# (wpf)

后端 未结 2 1637
自闭症患者
自闭症患者 2020-12-18 05:23

I have written a small program displaying sounds and images on the screen when pushing any button. I always start it when one of my little kids crawls onto my lap and start

相关标签:
2条回答
  • 2020-12-18 05:41

    You'll need a keyboard hook. Unfortunately, this has to be done with P/Invoke; it can't be done with managed code.

    Check out Baby Smash! by Scott Hanselman. It's hosted on code plex at http://www.codeplex.com/babysmash Github at https://github.com/shanselman/babysmash

    Alternatively, check out ShapeShow on CodeProject, which is similar.

    0 讨论(0)
  • 2020-12-18 05:41

    See http://msdn.microsoft.com/en-us/library/system.windows.input.key(v=VS.90).aspx

    At the bottom you'll see a simple example, I think what you're looking for is something along these lines:

    left windows key: System.Windows.Input.Key.LWin

    right windows key: System.Windows.Input.Key.RWin

    example:

    private void OnKeyDownHandler(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.LWin) {
            textBlock1.Text = "You Entered: " + textBox1.Text;
        }
    }
    
    0 讨论(0)
提交回复
热议问题