doing mouseclick with api

This is a discussion on doing mouseclick with api within the C++ Programming forums, part of the General Programming Boards category; i am trying to figure out what the api is for a simple left mouse click ive got the cordinates ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    317

    doing mouseclick with api

    i am trying to figure out what the api is for a simple left mouse click
    ive got the cordinates set .
    anyone help me?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Never tried it but WindowFromPoint and SendMessage with WM_LBUTTONDOWN/WM_LBUTTONUP should work.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    Quote Originally Posted by Quantum1024
    Never tried it but WindowFromPoint and SendMessage with WM_LBUTTONDOWN/WM_LBUTTONUP should work.
    i cant get this to work
    SendMessage(WM_LBUTTONDOWN);

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I managed to get it to work. PostMessage is realy a better solution since there's no need for the program to wait for the message to be handled.
    Code:
    void Click(int x, int y)
    {
    	POINT p;
    	p.x=x;
    	p.y=y;
    	HWND hWnd=WindowFromPoint(p);
    	if (ScreenToClient(hWnd, &p))
    	{
    		PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(p.x, p.y));
    		PostMessage(hWnd, WM_LBUTTONUP, 0, MAKELONG(p.x, p.y));
    	}
    }

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    thanks alot worksgreat

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    what would i use for arrowdown or arrowup or left and right ?
    to press down these i mean

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Wm_keydown/wm_keyup

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    its saying this
    error C2660: 'PostMessageA' : function does not take 3 parameters
    Code:
    void Click(int x, int y)
    {
     POINT p;
     p.x=x;
     p.y=y;
     HWND hWnd=WindowFromPoint(p);
     if (ScreenToClient(hWnd, &p))
     {
      PostMessage(hWnd, WM_KEYDOWN, MK_LBUTTON, MAKELONG(p.x, p.y)); //WM_LBUTTONDOWN
      PostMessage(hWnd, WM_KEYDOWN, MAKELONG(p.x, p.y));
     }
    }

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    In your second call to PostMessage you left out one paramater, also the wParam and lParam don't have the same meaning as with WM_LBUTTONDOWN and WM_LBUTTONUP.
    take a look at this http://msdn.microsoft.com/library/de...wm_keydown.asp

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    i never seem to be able to understand msdn
    is there a chance you could paste the code like you did from the other

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You can send 1 up arrow keystroke like this.
    Code:
    PostMessage(hWnd, WM_KEYDOWN, VK_UP, 1);
    Sending the down arrow key is left as an excercise.

  13. #13
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    7 C:\Dev-Cpp\main.cpp `hWnd' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears in.)

    void f()
    {
    PostMessage(hWnd, WM_KEYDOWN, VK_UP, 1);
    }

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    void arrow(int x, int y)
    {
    POINT p;
    p.x=x;
    p.y=y;
    HWND hWnd=WindowFromPoint(p);
    if (ScreenToClient(hWnd, &p))
    {
    PostMessage(hWnd, WM_KEYDOWN, VK_UP, 1);

    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Want to learn Windows API for Game Programming
    By George M. in forum Windows Programming
    Replies: 15
    Last Post: 09-28-2008, 10:26 AM
  2. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 06:46 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. pthread api vs win32 thread api
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 11-20-2001, 07:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21