How can I capture Ctrl + Alt + K + P keys on a C# form? thanks
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can use GetKeyState to get the status of the other keys when one of the keys in the combination has been pressed. Here's an example on a form.
It is a chord, you cannot detect it without memorizing having seen the first keystroke of the chord. This works:
See this great blog post about setting up hotkeys in c#
There's also a good article that explains all of this here
I'm not sure if you can. What you CAN do however, is the way Visual Studio does it. It has shortcuts like Ctrl + K, C. You first press Ctrl+K, then hold down Ctrl and press C. In your case, you could check for Ctrl+Alt+K,P.
You can first check for only Ctrl+Alt+K as done in the other answers, then set a member variable/flag to indicate Ctrl+Alt+K has been pressed. In the same method where you check for K you can check for P, and if the flag you just set was set to true, do whatever you need to do. Otherwise set the flag back to false.
Rough pseudo-code:
Hope that's clear enough.
MessageFilters
can help you in this case.Now in your C# WindowsForm, register the MessageFilter for capturing key-strokes and combinations.