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. Selecting Text - Pls Help!!

Selecting Text - Pls Help!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
3 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    c121hains
    wrote on last edited by
    #1

    :confused: This should be easy. All i want to do is have some text highlighted in a control in another window. The control doesn't respond to any EM_* messages so i'm simulating the selection of text by sending a series of VK_RIGHT and VK_SHIFT key presses. The problem is that it the 'right arrow' key gets pressed but the control doesn't have the effect of the 'shift' key. I know it gets pressed because once i move around in the control, the shift key is still down (when i uncomment the shift release key press - see last line of below method)!! I have to do it this way as i have no other choice. Here's the code: window->BringWindowToTop(); //THIS PART WORKS //Same effect as pressing the right arrow key 10 times for (int a = 0; a < 10; a++){ wnd->SendMessage(WM_KEYDOWN, VK_RIGHT, 0); wnd->SendMessage(WM_KEYUP, VK_RIGHT, 0); } //This part should select the next 5 characters of text. //Simulates holding down shift and pressing 'Right Arrow' key 5 times INPUT input[2]; for (int b = 0; b < 5; b++){ input[0] = GetKeyboardInput(VK_LSHIFT, 0); input[1] = GetKeyboardInput(VK_RIGHT, 0); //Press down shift and right arrow key SendInput(2, input, sizeof(INPUT)); input[1] = GetKeyboardInput(VK_RIGHT, 2); //Release right arrow key SendInput(2, input, sizeof(INPUT)); } //Release the shift key input[0] = GetKeyboardInput(VK_LSHIFT, 2); SendInput(2, input, sizeof(INPUT)); INPUT CFindInWindowDlg::GetKeyboardInput(short key, int downUp) { INPUT input; input.type = 0x01; //INPUT_KEYBOARD input.ki.dwExtraInfo = 0; input.ki.time = 0; input.ki.wScan = 0; input.ki.wVk = key; input.ki.dwFlags = downUp; return input; } Any help would be greatly appreciated. My head is going to explode! :wtf:

    J 1 Reply Last reply
    0
    • C c121hains

      :confused: This should be easy. All i want to do is have some text highlighted in a control in another window. The control doesn't respond to any EM_* messages so i'm simulating the selection of text by sending a series of VK_RIGHT and VK_SHIFT key presses. The problem is that it the 'right arrow' key gets pressed but the control doesn't have the effect of the 'shift' key. I know it gets pressed because once i move around in the control, the shift key is still down (when i uncomment the shift release key press - see last line of below method)!! I have to do it this way as i have no other choice. Here's the code: window->BringWindowToTop(); //THIS PART WORKS //Same effect as pressing the right arrow key 10 times for (int a = 0; a < 10; a++){ wnd->SendMessage(WM_KEYDOWN, VK_RIGHT, 0); wnd->SendMessage(WM_KEYUP, VK_RIGHT, 0); } //This part should select the next 5 characters of text. //Simulates holding down shift and pressing 'Right Arrow' key 5 times INPUT input[2]; for (int b = 0; b < 5; b++){ input[0] = GetKeyboardInput(VK_LSHIFT, 0); input[1] = GetKeyboardInput(VK_RIGHT, 0); //Press down shift and right arrow key SendInput(2, input, sizeof(INPUT)); input[1] = GetKeyboardInput(VK_RIGHT, 2); //Release right arrow key SendInput(2, input, sizeof(INPUT)); } //Release the shift key input[0] = GetKeyboardInput(VK_LSHIFT, 2); SendInput(2, input, sizeof(INPUT)); INPUT CFindInWindowDlg::GetKeyboardInput(short key, int downUp) { INPUT input; input.type = 0x01; //INPUT_KEYBOARD input.ki.dwExtraInfo = 0; input.ki.time = 0; input.ki.wScan = 0; input.ki.wVk = key; input.ki.dwFlags = downUp; return input; } Any help would be greatly appreciated. My head is going to explode! :wtf:

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      c121hains wrote: The problem is that it the 'right arrow' key gets pressed but the control doesn't have the effect of the 'shift' key. I know it gets pressed because once i move around in the control, the shift key is still down (when i uncomment the shift release key press - see last line of below method)!! Try the following. I tested it with an edit control in the same dialog and it worked... May or may not work in your case, but I hope you'll let us know :)

      static INPUT GetKeyboardInput(short key, DWORD dwFlags)
      {
         INPUT input;
       
         input.type = INPUT_KEYBOARD;
         input.ki.dwExtraInfo = 0;
         input.ki.time = 0;
         input.ki.wScan = 0;
         input.ki.wVk = key;
         input.ki.dwFlags = dwFlags;
       
         return input;
      }
       
      void CFindInWindowDlg::Select(CWnd* window, int start, int count)
      {
         window->BringWindowToTop();
       
         INPUT input[4];
         input[0] = GetKeyboardInput(VK_SHIFT, KEYEVENTF_EXTENDEDKEY);
         input[1] = GetKeyboardInput(VK_SHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY);
         input[2] = GetKeyboardInput(VK_RIGHT, 0);
         input[3] = GetKeyboardInput(VK_RIGHT, KEYEVENTF_KEYUP);
       
         // move to start
         for (int i = 1; i < start; i++)
         {
            SendInput(2, &input[2], sizeof(INPUT));
         }
       
         // press shift key
         SendInput(1, &input[0], sizeof(INPUT));
       
         // move cursor
         for (int j = 0; j < count; j++)
         {
            SendInput(2, &input[2], sizeof(INPUT));
         }
       
         // release shift key
         SendInput(1, &input[1], sizeof(INPUT));
      }

      I think your problem was: 1. Not using KEYEVENTF_EXTENDEDKEY for the shift key. 2. Sending too many shift keys (where you say "release the right key" you were actually sending [shift down + right up], and after the loop you were sending [shift up + right up]). Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

      C 1 Reply Last reply
      0
      • J Jose Lamas Rios

        c121hains wrote: The problem is that it the 'right arrow' key gets pressed but the control doesn't have the effect of the 'shift' key. I know it gets pressed because once i move around in the control, the shift key is still down (when i uncomment the shift release key press - see last line of below method)!! Try the following. I tested it with an edit control in the same dialog and it worked... May or may not work in your case, but I hope you'll let us know :)

        static INPUT GetKeyboardInput(short key, DWORD dwFlags)
        {
           INPUT input;
         
           input.type = INPUT_KEYBOARD;
           input.ki.dwExtraInfo = 0;
           input.ki.time = 0;
           input.ki.wScan = 0;
           input.ki.wVk = key;
           input.ki.dwFlags = dwFlags;
         
           return input;
        }
         
        void CFindInWindowDlg::Select(CWnd* window, int start, int count)
        {
           window->BringWindowToTop();
         
           INPUT input[4];
           input[0] = GetKeyboardInput(VK_SHIFT, KEYEVENTF_EXTENDEDKEY);
           input[1] = GetKeyboardInput(VK_SHIFT, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY);
           input[2] = GetKeyboardInput(VK_RIGHT, 0);
           input[3] = GetKeyboardInput(VK_RIGHT, KEYEVENTF_KEYUP);
         
           // move to start
           for (int i = 1; i < start; i++)
           {
              SendInput(2, &input[2], sizeof(INPUT));
           }
         
           // press shift key
           SendInput(1, &input[0], sizeof(INPUT));
         
           // move cursor
           for (int j = 0; j < count; j++)
           {
              SendInput(2, &input[2], sizeof(INPUT));
           }
         
           // release shift key
           SendInput(1, &input[1], sizeof(INPUT));
        }

        I think your problem was: 1. Not using KEYEVENTF_EXTENDEDKEY for the shift key. 2. Sending too many shift keys (where you say "release the right key" you were actually sending [shift down + right up], and after the loop you were sending [shift up + right up]). Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

        C Offline
        C Offline
        c121hains
        wrote on last edited by
        #3

        EXCELLENT! It works... it's alive!!!!!!!!! hehehe Thanks a million!:cool:

        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