我需要检测用户何时按下Ctrl+ V(无论窗口焦点如何 - 我的应用程序可能会被最小化)但我不能停止实际的粘贴操作。
我尝试了一些事情:(我成功地使用 RegisterHotKey 绑定到击键)
我有:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x312)
hotKey();
base.WndProc(ref m);
}
我尝试了以下方法:
void hotKey()
{
SendKeys.SendWait("^v"); //just puts 'v' instead of clipboard contents
}
和
void hotKey()
{
SendKeys.SendWait(ClipBoard.GetText());
/* This works, but since Ctrl is still down, it triggers
* all the shortcut keys for the app, e.g. if the keyboard
* contains 's' then instead of putting 's' in the app, it
* calls Ctrl+S which makes the app think the user wants
* to save.
*/
}
目前,我唯一可行的解决方案是绑定到不同的东西,例如Ctrl+B然后调用SendKeys.SendWait("^v");,但这并不理想。
一个理想的解决方案是,如果我的窗口首先没有拦截击键,只是做出了反应。