Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Copying to ClipBoard By using SendInput, Failure....[Solved]

Copying to ClipBoard By using SendInput, Failure....[Solved]

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestionannouncement
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EuiyongYun
    wrote on last edited by
    #1

    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");
    }
    

    }

    V 1 Reply Last reply
    0
    • E EuiyongYun

      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");
      }
      

      }

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Why are you using KEYEVENTF_UNICODE flag?

      E 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Why are you using KEYEVENTF_UNICODE flag?

        E Offline
        E Offline
        EuiyongYun
        wrote on last edited by
        #3

        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");
        }
        

        }

        V 1 Reply Last reply
        0
        • E EuiyongYun

          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");
          }
          

          }

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups