将粘贴消息发送到活动 window 的焦点控件
Sending paste message to active window's focused control
我想拦截一个热键(特别是 CTRL V
),它将以某种方式与我的应用程序交互。我可以使用 RegisterHotKey
method. When I press CTRL V
I want the focused window/control to also receive the WM_PASTE
message. I've tried sending it trough SendMessage
全局注册热键,但它似乎不起作用。我最终取消注册热键,将 ^v
发送到当前 window,然后重新注册热键。
private static void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
_hook.KeyPressed -= Hook_KeyPressed;
_hook.Dispose();
SendKeys.Send("^v");
_hook = new KeyboardHook();
_hook.RegisterHotKey(global::ClipMaster.ModifierKeys.Control, Keys.V);
_hook.KeyPressed += Hook_KeyPressed;
}
这确实有效,但它会阻止鼠标(和 window)大约半秒钟。我也担心它在某些应用程序中不起作用,虽然我不知道我可以举什么例子。
我不确定你想用那个钩子实现什么,因为从代码示例中无法理解它。
假设您这样做是出于审计原因(或某种监控),我建议您查看 WM_HOTKEY 消息的 return 值。它可以 "say" 消息未被处理,因此允许通过其他逻辑(例如其他挂钩)进一步处理 Ctrl-V。
另外,我建议使用替代方法来重新发送 Ctrl-V,而不是 SendKeys class,因为它知道时间问题。您是否考虑改为发布消息?
我还通过使用 lower level key pressing for hooking.
找到了挂钩本身的替代方法
如果有帮助请告诉我。
我想拦截一个热键(特别是 CTRL V
),它将以某种方式与我的应用程序交互。我可以使用 RegisterHotKey
method. When I press CTRL V
I want the focused window/control to also receive the WM_PASTE
message. I've tried sending it trough SendMessage
全局注册热键,但它似乎不起作用。我最终取消注册热键,将 ^v
发送到当前 window,然后重新注册热键。
private static void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
_hook.KeyPressed -= Hook_KeyPressed;
_hook.Dispose();
SendKeys.Send("^v");
_hook = new KeyboardHook();
_hook.RegisterHotKey(global::ClipMaster.ModifierKeys.Control, Keys.V);
_hook.KeyPressed += Hook_KeyPressed;
}
这确实有效,但它会阻止鼠标(和 window)大约半秒钟。我也担心它在某些应用程序中不起作用,虽然我不知道我可以举什么例子。
我不确定你想用那个钩子实现什么,因为从代码示例中无法理解它。
假设您这样做是出于审计原因(或某种监控),我建议您查看 WM_HOTKEY 消息的 return 值。它可以 "say" 消息未被处理,因此允许通过其他逻辑(例如其他挂钩)进一步处理 Ctrl-V。 另外,我建议使用替代方法来重新发送 Ctrl-V,而不是 SendKeys class,因为它知道时间问题。您是否考虑改为发布消息?
我还通过使用 lower level key pressing for hooking.
找到了挂钩本身的替代方法如果有帮助请告诉我。