在C#中捕获Windows键(WPF) [英] Capturing the windows key in c# (wpf)

查看:129
本文介绍了在C#中捕获Windows键(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小程序,当按下任何按钮时,该程序都会在屏幕上显示声音和图像.我总是在我的一个小孩爬到我的大腿上并开始随机敲击琴键时开始操作.

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 hitting the keys, of course, randomly.

除了2个按键外,其他所有按键都可以正常工作,其中一个按键是ON/OFF开关,另一个按键是Windows键. (我相信它相当于CTRL-ESC)我可以在按下它时对其进行拦截,但只能在开始菜单显示之后进行.

It works fine except for 2 keys, one of them being the ON/OFF switch, the other being the Windows-key. (the CTRL-ESC equivalent I believe) I can intercept it as it is pressed, but only after the startmenu is showing.

我使用的事件是UIElement.KeyDown,到目前为止我只想出:(e是KeyEventArgs)

The event I use is the UIElement.KeyDown and all I could came up with so far is : (the e being KeyEventArgs)

            if (e.Key == Key.LWin) e.Handled = true;

但恐怕开始窗口已经显示.

but than the start window is already showing I'm afraid.

我已经有1个答案,但是非常想知道是否有wpf支持吗?

I have already 1 answer but would very much like to know if there's any wpf-support?

我怀疑无法对主开/关开关进行编程?否则,也将欢迎您的任何帮助.

I suspect programming the main on/off switch might not be possible? Otherwise, any help there would be welcome too..

推荐答案

您将需要

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

查看Scott Hanselman的 Baby Smash!.它托管在 code plex上,网址为 http://www.codeplex.com/babysmash Github,位于 https://github.com/shanselman/babysmash

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

或者,在CodeProject上查看 ShapeShow .

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

这篇关于在C#中捕获Windows键(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆