我有MFC应用程序,它可以在热键上调用(应该正在运行,只需将它带到前面),使用剪贴板数据发送到其中一个文本框,
SendMessage(hWnd,WM_PASTE,0,0);
到目前为止一切正常。
我们得到了新的要求,我们应该能够使用热键将所选文本复制到剪贴板(不使用Ctrl + C ),然后启动我们的应用程序。
我尝试使用SendMessage(WM_COPY)
,但无效。
请建议如何在剪贴板上获取任何其他应用程序的选定文本。
答案 0 :(得分:1)
最后我自己得到了答案。
我必须使用SendInput
,以下是示例代码,
INPUT ip;
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
// Press the "Ctrl" key
ip.ki.wVk = VK_CONTROL;
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
// Press the "C" key
ip.ki.wVk = 'C';
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
// Release the "C" key
ip.ki.wVk = 'C';
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
// Release the "Ctrl" key
ip.ki.wVk = VK_CONTROL;
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));