我编写了一个小程序,在按下任何按钮时在屏幕上显示声音和图像.当我的一个小孩爬到我的腿上并开始敲击琴键时,我总是启动它,当然,随机的.
除了 2 个键外,它工作正常,其中一个是 ON/OFF 开关,另一个是 Windows 键.(我相信CTRL-ESC等价物)我可以在按下它时拦截它,但只有在开始菜单显示之后.
我使用的事件是 UIElement.KeyDown,到目前为止我所能想到的是:(e 是 KeyEventArgs)
if (e.Key == Key.LWin) e.Handled = true;
但恐怕开始窗口已经显示出来了.
我已经有 1 个答案,但很想知道是否有任何 wpf 支持?
我怀疑可能无法对主开关进行编程?否则,也欢迎任何帮助..
你需要一个 键盘挂钩.不幸的是,这必须通过 P/Invoke 来完成;托管代码无法做到这一点.
查看 Scott Hanselman 的 Baby Smash!.它托管在 http://www.codeplex.com/babysmashcode plex> Github 在 https://github.com/shanselman/babysmash
或者,查看 CodeProject 上的 ShapeShow,类似.p>
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.
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.
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.
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.
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.
这篇关于在 c# (wpf) 中捕获 windows 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!