Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlClick inactive window w/o activating it?


  • Please log in to reply
5 replies to this topic
Vailent
  • Members
  • 8 posts
  • Last active: Jun 04 2013 08:47 AM
  • Joined: 23 May 2013

So, I've been banging my head over this the last three days straight...

 

I want to be able to send a click to an inactive window, in this case mspaint, but I do not want the window to activate.  The script I put together works, but not as intended; it will click, but only in the center of the screen (its a second monitor btw)... I've tried swapping ControlClick for "Send {click}" and that does work as far as clicking where I want it to click, but it also activates the window in the process, which is something I do not want.

#NoEnv
#MaxThreadsPerHotkey, 1
#SingleInstance, Force
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
SendMode, Event
SetControlDelay 0

WinGet, WowWinId, List

1::
{
		wingetpos,x1,y1,,,A
		DllCall("SetCursorPos", "int", 1650+x1, "int", 700+y1)
		ControlClick,, Untitled - Paint,2, LEFT,, NA
		DllCall("SetCursorPos", "int", 550+x1, "int", 550+y1)
Return
}

2::
{
		wingetpos,x1,y1,,,A
		DllCall("SetCursorPos", "int", 1900+x1, "int", 720+y1)
		ControlClick,, Untitled - Paint,2, LEFT,, NA
		DllCall("SetCursorPos", "int", 550+x1, "int", 550+y1)
   Return
}

3::
{
		wingetpos,x1,y1,,,A
		DllCall("SetCursorPos", "int", 2200+x1, "int", 700+y1)
		ControlClick,, Untitled - Paint,2, LEFT,, NA
		DllCall("SetCursorPos", "int", 550+x1, "int", 550+y1)
   Return
}

If you are wondering about all the coordmodes up top, I eventually want to try the same idea, only with clicking in regions.

Ei:

~RButton::    
If MouseInRange(130,780,469,579)   
;Stuff

What really has me annoyed is that I swear I got this working last night, but this afternoon it just refused to cooperate.



Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

You can actually specify the coordinates when you use the ControlClick command:

ControlClick, x255 y152, WinTitle


Vailent
  • Members
  • 8 posts
  • Last active: Jun 04 2013 08:47 AM
  • Joined: 23 May 2013

I should mention that with the script I initially posted, the mouse would register as being in the designated area, but clicked the center of the screen anyway. 

 

 

 

You can actually specify the coordinates when you use the ControlClick command:

ControlClick, x255 y152, WinTitle

 

Ok, so going with my untitled ms paint I should be able to do:

2:: 
ControlClick, x1900 y720, Untitled - Paint,, LEFT,, NA

Right? 

 

I must be missing something, because it doesn't work at all... Do I need to add something in the beginning? 



Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

As per docs:

Mode 1 (Position): Specify the X and Y coordinates relative to the target window's upper left corner. The X coordinate must precede the Y coordinate and there must be at least one space or tab between them. For example: X55 Y33. If there is a control at the specified coordinates, it will be sent the click-event at those exact coordinates. If there is no control, the target window itself will be sent the event (which might have no effect depending on the nature of the window). Note: In this mode, the X and Y option letters of the Options parameter are ignored.

Try using Window Spy to check if there is a control at those coordinates. If not, you might need to resort using another method. Btw, based on the coordinates you provided, are you trying to send a click event on the "Zoom In/Zoom Out" buttons? You can also operate on the control directly by specifying its ClassNN instead of the coordinates. (e.g ControlClick, Button1, Untitled - Paint,, LEFT,, NA) or if you want to use its hWnd instead of its ClassNN, leave parameter 2 blank and specify its hWnd as the WinTitle parameter (e.g ControlClick,, % "ahk_id " ConrolhWnd)



Vailent
  • Members
  • 8 posts
  • Last active: Jun 04 2013 08:47 AM
  • Joined: 23 May 2013
2:: ControlClick, Button1, Untitled - Paint,, LEFT,, NA

Does not work ether.  Even when replacing "Untitled - Paint" with "ahk_id MSPaintApp"

 

The coordinates I listed are just below the center of the screen in Mspaint's canvas area, so no, there are no special controls there.  I'm just trying to get it to place a dot in the correct set of coordinates. 

 

ClassNN:    Afx:2e0000:81

Which is a huge white area, so even window spy does not indicate anything special.

 

While trying to figure it out on my own, I did come across a few threads suggesting certain programs block controlclick, but as Mspaint is a pretty basic program, I do not believe it would be one such program.



Vailent
  • Members
  • 8 posts
  • Last active: Jun 04 2013 08:47 AM
  • Joined: 23 May 2013
2:: ControlClick, x700 y700, Untitled - Paint, , Left, 1, NA

I got this script here to work, and I figured out what the problem is...

 

ControlClick cannot send clicks to my 2nd monitor where my initial coordinates (x1900 y720) were located.

 

Now, I dont suppose anyone out there knows how I would go about sending a controlclick to a second monitor's coordinates? lol