CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: sendinput

  1. #1
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    sendinput

    i used
    Code:
      double fScreenWidth    = ::GetSystemMetrics( SM_CXSCREEN )-1; 
      double fScreenHeight  = ::GetSystemMetrics( SM_CYSCREEN )-1; 
      double fx = pt.x*(65535.0f/fScreenWidth);
      double fy = pt.y*(65535.0f/fScreenHeight);
      INPUT  Input={0};
      Input.type      = INPUT_MOUSE;
      Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN;
      Input.mi.dx = fx;
      Input.mi.dy = fy;
      ::SendInput(1,&Input,sizeof(INPUT));
    to input a mouse click, but the code mouves the cursor. is there a way without moving the cursor?

  2. #2
    Join Date
    Nov 2005
    Posts
    63

    Re: sendinput

    SendMessage allows you to send BN_CLICKED messages to a window that you have the handle of.

  3. #3
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: sendinput

    i Didn't Get your Question. if you Simply want to Click Something through your code you can do by Following Example . Which will Generate a Click Event on a Button .

    Code:
    ::SendMessage(hwndChild,WM_COMMAND,MAKELONG(00000002,BN_CLICKED),NULL); 
    
    //hwndChild handle of the Window
    //id of Control to whom you want to click
    That's all you have to do.

    Thanx

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    Re: sendinput

    Quote Originally Posted by dave2k
    i used
    Code:
      double fScreenWidth    = ::GetSystemMetrics( SM_CXSCREEN )-1; 
      double fScreenHeight  = ::GetSystemMetrics( SM_CYSCREEN )-1; 
      double fx = pt.x*(65535.0f/fScreenWidth);
      double fy = pt.y*(65535.0f/fScreenHeight);
      INPUT  Input={0};
      Input.type      = INPUT_MOUSE;
      Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN;
      Input.mi.dx = fx;
      Input.mi.dy = fy;
      ::SendInput(1,&Input,sizeof(INPUT));
    to input a mouse click, but the code mouves the cursor. is there a way without moving the cursor?
    If you don’t want to move the cursor why you are passing the MOUSEEVENTF_MOVE flag?
    Simply omit it.

    Anyway look at this FAQ.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: sendinput

    i did omit MOUSEEVENTF_MOVE, but it doesn't work! try it!

  6. #6
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: sendinput

    Omit also MOUSEEVENTF_ABSOLUTE!
    Please don't forget to rate users who helped you!

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: sendinput

    Quote Originally Posted by dave2k
    i did omit MOUSEEVENTF_MOVE, but it doesn't work! try it!
    Look at the FAQ i posted you in my previous post.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  8. #8
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: sendinput

    let me clarify, i need to click a window at point 10, 10, without moving the mouse cursor from it's current position. all your faq examples seem to involve either moving the cursor or clicking where it is currently.

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: sendinput

    Quote Originally Posted by dave2k
    let me clarify, i need to click a window at point 10, 10, without moving the mouse cursor from it's current position. all your faq examples seem to involve either moving the cursor or clicking where it is currently.
    So whats the problem?

    • Save current cursor position.
    • Move the cursor to the place you need to click.
    • Perform the click.
    • return the cursor back to the saved position in stage A


    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  10. #10
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: sendinput

    my program needs to click buttons in the background when i am using the cursor for other stuff. is this a SendMessage job?

  11. #11
    Join Date
    Nov 2005
    Posts
    63

    Re: sendinput

    Are you trying to make it click a control like a button, or trying to send a mouse click to the specific location of 10,10 in the window and there is no button there?

  12. #12
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: sendinput

    Just Check out My Previous Post. this will help you in Sending a click event to any Button.

    Thanx

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