通过捕捉重点ProcessCmdKey序列 [英] Capture Key Sequence via ProcessCmdKey
问题描述
我在应用程序重写ProcessCmdKey并可以得到调节剂(如:Alt + Ctrl + X)的任何一个按键。我想要做的是模仿说ReSharper的短切处理,用户按住Ctrl键,然后R,M打开重构对话框
I override ProcessCmdKey in my application and can get any single keypress with modifiers (eg. Alt+Ctrl+X). What I want to do is mimic the short cut handling of say ReSharper where the user holds down the control key and then R, M to open the refactor dialog
我已经找到大量引用捕获键加修饰的组合,但没有多少的顺序。有这样捕获多个关键起伏在C#中但它使用在KeyDown事件。
I have found plenty of references to capture key plus modifier combinations but not much for the sequence. There is this Capture Multiple key downs in C# but it uses the KeyDown Event.
也有重点矿区象这样的例子的 http://www.codeproject.com/KB/system/simple_key_log.aspx ,捕捉一切,并使用本地调用。
There are also key mining examples such as this http://www.codeproject.com/KB/system/simple_key_log.aspx that capture everything and use native calls.
我是能致以ProcessCmdKey处理键序列或做我需要到别处?因为我有一大批ProcessCmdKey拍摄的快捷键我宁可不要再次启动如果可能的话
Am I able to extend my ProcessCmdKey to handle the key sequences or do I need to look elsewhere? Since I have a large number of shortcuts captured in ProcessCmdKey I would rather not have to start again if possible
感谢
推荐答案
为了达到你想要你只需要保持的KeyPress
事件序列跟踪的功能。
In order to achieve the functionality you want you simply need to keep track of the sequence of KeyPress
events.
您可以创建一个类来跟踪 ProcessCmdKey
按下的最后一个键组合。如果特定的组合不匹配映射的命令,但它是可以将其存储在你的类序列的第一个元素。那么接下来的时间 ProcessCmdKey
启动检查新的 KeyPressTracker
类,以确定是否序列已启动。如果它然后检查新的按键组合是你指定一个的第二个元素。请参阅下面的伪代码示例:
You can create a class to keep track of the last key combination that was pressed in ProcessCmdKey
. If that particular combination does not match a mapped command but it is the first element of a sequence you can store it in your class. Then the next time ProcessCmdKey
is activated check your new KeyPressTracker
class to determine if a sequence has been started. If it has then check if the newly pressed key combination is the second element of one you specify. Please see the pseudocode example below:
第1步: ProcessCmdKey
被激活。该组合键是<大骨节病>按Ctrl + R 骨节病>,这不符合要处理一个命令,但是它是要使用(<大骨节病>按Ctrl + R + M <序列的第一个元素。/骨节病>)
Step 1: ProcessCmdKey
is activated. The key combination is Ctrl+R, this does not match a command that you want to process but it is the first element of a sequence that you want to use (Ctrl+R+M).
第二步:新一类存储此按键创建跟踪的最后一个按键的。
Step 2: Store this key-press in a new class you created to keep track of the last key-press.
KeyPressTracker.Store(KeyCode, Modifiers);
第3步: ProcessCmdKey
启动第二次。这一次,组合键<大骨节病>按Ctrl + M 骨节病>这是不是一个按键,我们正在寻找,但一个序列的第二个元素。我们检查使用新的 KeyPressTracker
类上次存储的按键。这将允许你匹配一个序,如<大骨节病>按Ctrl + R 骨节病>和<大骨节病>按Ctrl + M 骨节病>。
Step 3: ProcessCmdKey
is activated a second time. This time, the key combination is Ctrl+M which is not a key-press we're looking for but is the second element of a sequence. We check the last stored keypress using the new KeyPressTracker
class. This will allow you to match a "sequence" such as Ctrl+R and Ctrl+M.
var lastKeyPress = KeyPressTracker.GetLastKeyPress();
if (lastKeyPress == "Ctrl+R" && currentKeyPress == "Ctrl+M")
{
// Show Refactor dialog
}
这篇关于通过捕捉重点ProcessCmdKey序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!