Making “global” hotkeys in WPF

匆匆过客 提交于 2019-12-08 06:38:17

问题


I'm programming an application consisting of three usercontrols in an main window. In one of the usercontrols, there's a slider that needs to be controllable by keyboard input. The left arrow should decrease value, right button increase and so on. I have this work, but only when the slider has focus. If some other control has focus, I cant make it work at all.

Is it possible to define "global" hotkeys? IE keys that trigger the same event or function, no matter where the focus is? Hope I've made myself clear enough...


回答1:


I have never tried this but If you have a command registered at the main window level with keys associated to it that might work. Keep in mind I have never done this but it is some thing you can try. If you are new to commands here is a blog post about it.

I have never rolled this my self but when using the built in past command I actually had to put code in to prevent it from happening in some cases.

I know this probably isn't much help but I hope it is enough to get you started.



来源:https://stackoverflow.com/questions/1271882/making-global-hotkeys-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!