CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2012
    Posts
    20

    Easy but mind boggling question KEYBDINPUT

    I have a code here that should send the window ctrl+shift+left arrow. This should highlight the previous word. All that happens in the cursor moves to the beginning of the word as if only ctrl+left arrow were being pressed.

    Maybe there is an easier method for selecting the previous word or there is something with my code below?

    Code:
    	if(flagcheck==1)
    	{
    		//select word text
    		INPUT in1 = {INPUT_KEYBOARD};
    		INPUT in2 = {INPUT_KEYBOARD};
    		INPUT in3 = {INPUT_KEYBOARD};
    		INPUT in4 = {INPUT_KEYBOARD};
    		INPUT in5 = {INPUT_KEYBOARD};
    		INPUT in6 = {INPUT_KEYBOARD};
    		KEYBDINPUT k1 = {VK_CONTROL,0,0,0,0};
    		KEYBDINPUT k2 = {VK_SHIFT,0,0,0,0};
    		KEYBDINPUT k3 = {VK_LEFT,0,0,0,0};
    		KEYBDINPUT k4 = {VK_LEFT,0,KEYEVENTF_KEYUP,0,0};
    		KEYBDINPUT k5 = {VK_SHIFT,0,KEYEVENTF_KEYUP,,0};
    		KEYBDINPUT k6 = {VK_CONTROL,0,KEYEVENTF_KEYUP,0,0};
    		in1.ki = k1;
    		in2.ki = k2;
    		in3.ki = k3;
    		in4.ki = k4;
    		in5.ki = k5;
    		in6.ki = k6;
    		SendInput(1, &in1, sizeof(INPUT));
    		SendInput(1, &in2, sizeof(INPUT));
    		SendInput(1, &in3, sizeof(INPUT));
    		SendInput(1, &in4, sizeof(INPUT));
    		SendInput(1, &in5, sizeof(INPUT));
    		SendInput(1, &in6, sizeof(INPUT));
    	}

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Easy but mind boggling question KEYBDINPUT

    You need to form an array of INPUT structures and send them in a single SendInput call.

  3. #3
    Join Date
    Mar 2012
    Posts
    20

    Re: Easy but mind boggling question KEYBDINPUT

    I still get the same result, which results in the cursor moving to the left and still no highlighting. Furthermore, supposing the highlighting did work, the cursor doesn't move to the left until after the function completes, however I want the highlighting to occur instantly after the sendinput function is called.

    Is there a function that lets me highlight the previous word given the cursor position? I am trying to do this using as little resources as possible.

    ~thanks

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Easy but mind boggling question KEYBDINPUT

    Are you setting focus to the control first?

    At any rate, please show your modified code.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Easy but mind boggling question KEYBDINPUT

    It could be related to the fact you're not supplying a key scancode.
    You can get scancodes for keys via MapVirtualKey();

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Easy but mind boggling question KEYBDINPUT

    Also, try searching this forum for SendInput to find some working sample code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured