to capture system-wide keyboard events. But it also allows you to make those keyboard events pass through to other apps. For your particular case, you can define KbHookProc as:
private static int KbHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0) // This means we can intercept the event.
{
var hookStruct = (KbLLHookStruct)Marshal.PtrToStructure(
lParam,
typeof(KbLLHookStruct));
// Quick check if Ctrl key is down.
// See GetKeyState() doco for more info about the flags.
bool ctrlDown =
GetKeyState(VK_LCONTROL) != 0 ||
GetKeyState(VK_RCONTROL) != 0;
if (ctrlDown && hookStruct.vkCode == 0x56) // Ctrl+V
{
// Replace this with your custom action.
Clipboard.SetText("Hi");
}
}
// Pass to other keyboard handlers. Makes the Ctrl+V pass through.
return CallNextHookEx(_hookHandle, nCode, wParam, lParam);
}
I coded a quick and dirty WinForms app to illustrate this. For the full code listing, see
本文地址:IT屋 » C# Detecting Ctrl+V with RegisterHotKey but not intercepting it
我要当用户按下Ctrl + V键(无论窗口焦点 - 我的应用程序可能会被最小化)来检测。但我不能停止的实际粘贴操作。
我已经尝试了几件事情:(我成功地绑定到按键与RegisterHotKey)
我有:
保护覆盖无效的WndProc(参考消息M)
{
如果(m.Msg == 0x312)
热键();
base.WndProc(REF米);
}
和我已经试过如下:
无效热键()
{
SendKeys.SendWait(“^ v”); //只是把'V',而不是剪贴板内容
}
和
无效热键()
{
SendKeys.SendWait(ClipBoard.GetText());
/ *这工作,但由于按Ctrl仍下降,它会触发
*所有应用程序的快捷键,例如如果键盘
*包含'S',然后,而不是把“S”的应用程序,它
*调用Ctrl + S键,这使得应用程序认为用户希望
*进行保存。
* /
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-35347-2.html
让每个中国人觉醒
干嘛不把我大汉帝国虽远必诛的经验也集成进来