Copying to ClipBoard By using SendInput, Failure....[Solved]
-
Hi~ I wrote the following function to copy the selected part of NotePad. ( Sending Control+C Message ) However, it does not work! Only 'C' is printed in NotePad. Does anyone know why? >> OS : Windows10 >> Compiler : VisualStudio 2010
Send_KeyBoard_Control_C()
{
HWND notepad = ::FindWindow(__T("NotePad"), NULL );
if (notepad == NULL) {
return;
}
if (!::SetForegroundWindow(notepad)) {
return;
}int sendCount = 0; INPUT input; // Press the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.wScan = 0; input.ki.dwFlags = 0; sendCount += SendInput(1, &input, sizeof(INPUT)); // Press the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wScan = 'C'; input.ki.dwFlags = KEYEVENTF\_UNICODE; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wScan = 'C'; input.ki.dwFlags = KEYEVENTF\_UNICODE | KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.wScan = 0; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); if ( sendCount != 4 ) { TRACE("fail\\n"); }
}
-
Hi~ I wrote the following function to copy the selected part of NotePad. ( Sending Control+C Message ) However, it does not work! Only 'C' is printed in NotePad. Does anyone know why? >> OS : Windows10 >> Compiler : VisualStudio 2010
Send_KeyBoard_Control_C()
{
HWND notepad = ::FindWindow(__T("NotePad"), NULL );
if (notepad == NULL) {
return;
}
if (!::SetForegroundWindow(notepad)) {
return;
}int sendCount = 0; INPUT input; // Press the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.wScan = 0; input.ki.dwFlags = 0; sendCount += SendInput(1, &input, sizeof(INPUT)); // Press the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wScan = 'C'; input.ki.dwFlags = KEYEVENTF\_UNICODE; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wScan = 'C'; input.ki.dwFlags = KEYEVENTF\_UNICODE | KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.wScan = 0; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); if ( sendCount != 4 ) { TRACE("fail\\n"); }
}
Why are you using KEYEVENTF_UNICODE flag?
-
Why are you using KEYEVENTF_UNICODE flag?
Thanks a lot! I fixed it thanks to you.
void Send_KeyBoard_Control_C()
{
HWND notepad = ::FindWindow(__T("NotePad"), NULL );
if (notepad == NULL) {
return;
}if (!::SetForegroundWindow(notepad)) { return; } int sendCount = 0; INPUT input; // Press the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; sendCount += SendInput(1, &input, sizeof(INPUT)); // Press the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = 'C'; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = 'C'; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); if ( sendCount != 4 ) { TRACE("fail\\n"); }
}
-
Thanks a lot! I fixed it thanks to you.
void Send_KeyBoard_Control_C()
{
HWND notepad = ::FindWindow(__T("NotePad"), NULL );
if (notepad == NULL) {
return;
}if (!::SetForegroundWindow(notepad)) { return; } int sendCount = 0; INPUT input; // Press the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; sendCount += SendInput(1, &input, sizeof(INPUT)); // Press the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = 'C'; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "C" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = 'C'; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); // Release the "Ctrl" key ZeroMemory(&input, sizeof(INPUT)); input.type = INPUT\_KEYBOARD; input.ki.wVk = VK\_CONTROL; input.ki.dwFlags = KEYEVENTF\_KEYUP; sendCount += SendInput(1, &input, sizeof(INPUT)); if ( sendCount != 4 ) { TRACE("fail\\n"); }
}
:)