Page 1 of 2

Click on window while user use mouse

Posted: Sun Jul 18, 2010 11:58 am
by oftit
Hi all
How can you click on a window without using the main mouse? Like My program.exe clicks on Internet Explorer while the user is using the mouse to do some work? So make the program click on a window without effecting the main mouse?

Thanks in advance

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 12:03 pm
by srod
Use FindWindow_() or some such to retrieve the window handle and then send a #WM_NCLBUTTONDOWN message (with suitable parameters) to the window in question.

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 2:44 pm
by oftit
So like this?

Code: Select all

xPos = 545
yPos = 300
SendMessage_(FindWindow_(0, "PureBasic 4.50 (x64)"), #WM_NCLBUTTONDOWN, xPos, yPos)

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 2:56 pm
by srod
No. You are misuing the message parameters.

Here's one where we simulate a double-click to maxmimize notepad etc. Just check the window title of the notepad window before running.

Code: Select all

RunProgram("notepad.exe")
Repeat
  hWnd = FindWindow_(0, "Untitled - Notepad")
Until hWnd
SendMessage_(hWnd, #WM_NCLBUTTONDBLCLK, #HTCAPTION, 0)
If the code cannot find the notepad window then you will to kill the program through the debugger menu.

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 2:59 pm
by oftit
Ok that's working, thank you. But how do you specify position?

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 3:03 pm
by srod

Code: Select all

SendMessage_(hWnd, #WM_NCLBUTTONDBLCLK, #HTCAPTION, x + y<<16)
Remember though that for non-client messages, the coordinates are screen-coordinates (not client coordinates). That is they are relative to the top-left of the screen.

If you are sending such messages then, depending on exactly what you are trying to achieve, the actual coordinates may not be important anyhow. That is you can just pass a zero value.

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 3:13 pm
by oftit
Can not get it to work.
I want to left click on the window "Untitled - Notepad" in position x = 5, y = 29 from window's left-top corner?

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 3:51 pm
by RASHAD
Hi

Code: Select all

RunProgram("notepad.exe")
Repeat
  hWnd = FindWindow_(0, "Untitled - Notepad")
Until hWnd
ShowWindow_(hWnd, #SW_SHOWMAXIMIZED)
GetCursorPos_(cp.POINT)
SetCursorPos_(5,29)
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
SetCursorPos_(cp\x,cp\y)


Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 4:40 pm
by oftit
You still using the main mouse?

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 7:04 pm
by srod
oftit wrote:Can not get it to work.
I want to left click on the window "Untitled - Notepad" in position x = 5, y = 29 from window's left-top corner?
Client co-ordinates or window co-ordinates?

If you wish to click within the client-area then use #WM_LBUTTONDOWN.

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 9:10 pm
by oftit
Like this?:

Code: Select all

x = 24
y = 77
Repeat
  hWnd = FindWindow_(0, "PureBasic 4.50 (x64)")
Until hWnd
SendMessage_(hWnd, #WM_LBUTTONDOWN, #HTCAPTION, x + y)
SendMessage_(hWnd, #WM_LBUTTONUP, #HTCAPTION, x + y)
Or like this?:

Code: Select all

x = 24
y = 77
Repeat
  hWnd = FindWindow_(0, "PureBasic 4.50 (x64)")
Until hWnd
SendMessage_(hWnd, #WM_LBUTTONDOWN, #HTCLIENT, x + y)
SendMessage_(hWnd, #WM_LBUTTONUP, #HTCLIENT, x + y)
Can't get both to work?

Thanks for not getting irritated by me asking :oops:

Re: Click on window while user use mouse

Posted: Sun Jul 18, 2010 11:20 pm
by srod
You need to refer to MSDN rather than start guessing about api message parameters. You also haven't taken my cue in how to create the points structure... you need to place the y-coordinate in the upper word of the lParam parameter and the x-coordinate in the lower word. Use x + y<<16.

More importantly, you haven't actually said what it is you are trying to achieve? Do you require a non-client mouse click or a client area click? Are you wishing to instigate the click of a toolbar button for example?

I cannot help without knowing exactly what it is you are trying to achieve because, as it is, I am having to guess.

Re: Click on window while user use mouse

Posted: Mon Jul 19, 2010 10:30 am
by oftit
I did try on MSDN and they said something about Get_X_LParam() and Get_Y_LParam. And that the x has to be in lower word and y has to be in upper word?? Which I didn't understand.

My son likes to play a game while he is on MSN. So when he plays this game on OneMoreLevel.com it is very tuff, so he wants the program to click instead while he is watching the program completing the game. I know it is a weird purpose but you know children :P So I guess I want to click on the client area?

Or like when you reading on wikipedia and listening to music on youtube, the program will replay the song?

Thank you

Re: Click on window while user use mouse

Posted: Mon Jul 19, 2010 10:40 am
by srod
Well, is there a particular point in the client-area you wish to click? Is there a button in there that you wish to click?

Re: Click on window while user use mouse

Posted: Mon Jul 19, 2010 11:06 am
by oftit
No a java app?

So you can't click on a specified position?