How to click in two different programs at the same time? - autohotkey

I want to be able to start a timer at the same time that i start a video in media player classic & also be able to pause both at the same time.
lets say that i have to click in the timer the one tha tis in the top left of the image and then click f1 or else the script does not work... also if i want to click it again after the first time it does not work properly..
I tried the following code:
F1::
MouseClick, left, 146, 115
MouseClick, left, 87, 300
Return

I suppose that adding
CoordMode, Mouse, Screen
at the top of your script will help you achieve what you're looking to do.
However, I suggest you use ControlClick instead.
F1::
ControlClick, x87 y300, Hourglass,, Left
ControlClick, x100 y100, Media Player Classic,, Left
return
This will send a click to the x and y relative to each window regardless if they're on top or not (they cannot, however, be minimized)
(please note that you probably have to adjust the x and y coordinates)
https://autohotkey.com/docs/commands/CoordMode.htm
https://autohotkey.com/docs/commands/ControlClick.htm

From my (limited) experience, I believe even hotkeys will carry out actions sequentially i.e. one after the other, in most cases the time delay between clicks will be insignificant howeverwon't be exact.
If the timer (Hourglass) is something you have created yourself, I would maybe suggest adding another button or a hotkey specifically for this use case that adds; for example, a 0.5s delay before the timer begins & then starts the media 0.5s later allowing for them to work in tandem, but as far as starting both applications simultaneously I'm not aware of a method for this.
To clarify though, what was the actual issue with the quoted code above?

Related

ImageSearch command failing

I'm trying to create a hotkey that will find the google sheets "tools" menu, click on it, move down a few pixels and click on script editor. I could do this within google sheets but it doesn't have universal keybinds for this, I'd have to make a macro and I'd rather it just be universal.
SC163::
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\xx\Documents\AHK Scripts\gsheets-tools.bmp
if ErrorLevel = 2
tooltip Could not conduct the search.
else if ErrorLevel = 1
tooltip Image could not be found on the screen.
else
{
mousemove, %FoundX%, %FoundY%, 50
tooltip The image was found at %FoundX%x%FoundY%.
}
return
}
It was throwing error 2 until I hardcoded the entire image name. Now it only throws error 1, even if I have three copies of sheets open (one on each monitor). Is BMP not the best format to use here? I tried using
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *n30 C:\Users\xx\Documents\AHK Scripts\gsheets-tools.bmp
to see if adding that allowance would helps, but failure. Any tips for using image search correctly? This isn't some sophisticated game function, just trying to find a toolbar and click on it!
Try changing *n30 to just *30.
Also, by default, ImageSearch coordinates are per the active window and not the entire desktop, so using A_ScreenWidth and A_SreeenHeight might be problematic. While this isn't an issue if the window is maximized on your primary screen, it may present a problem if it's not maximized or is on a screen with a different resolution. If it's not maximized, it could be searching an area that goes beyond your display area, which might be an issue.
Possibly another issue (unverified) could be with Windows scaling. A lot of times a 2160p monitor defaults to 200% scaling (or is it 150%? w/e).
Since you're using BMP images, you may want to verify that it was saved as 16-bit or higher.
Notable quotes from the help file:
All operating systems support GIF, JPG, BMP, ICO, CUR, and ANI images (BMP images must be 16-bit or higher).
. . .
The region to be searched must be visible; in other words, it is not possible to search a region of a window hidden behind another window. By contrast, images that lie partially beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will obstruct any images beneath them.
I suggest you using this for Image Search
https://www.youtube.com/watch?v=aWRAtvJq9ZE
It is very simple and works pretty good!

Trigger AHK script based on the position of the mouse

Is it possible to trigger an AHK script based on the position of the mouse? Say, if I wanted to press a button or series of buttons on my keyboard if I move my mouse to the corner or edge of the screen. Also, can this be done multiple times per second until the mouse is moved out of the specified area?
All I could find from googling is AHK scripts for moving the mouse using the keyboard, when I want to do the opposite.
I did it, thanks Aaron and ahkcoder.
I got a little better feel with Up and Down instead of PgUp and PgDn, to anyone else, play with the timings until it's sufficient. You'll also need to modify the values for the edges of your screen.
; move up and down when mouse is at edges of screen
#Persistent
SetTimer, foo, 65
return
foo:
MouseGetPos, x, y, id, control
; ToolTip, %x% %y%
; will trigger only at edges of a full screen
if (y = 1087){
; bottom
send {Down}
send {Down}
send {Down}
; sleep, 300
}
else if(y = 8){
; top
send {Up}
send {Up}
send {Up}
}
return
Yes. Easiest way I can think of to do what you are asking is to use SetTimer and MouseGetPos to evaluate the position and if it matches than trigger your script.
The 2nd example code on the MouseGetPos is using SetTimer. This should get you headed in the right direction.

Matlab Impoint and Uicontrol

I'm more on the no0b side of coding, so I apologize in advance for stupid question and / or poor coding practice. Basically, I have a dream of being able to click, place an impoint, record the location of that impoint, and then click again for another point (and record the location of that point) until I hit the "Done" button. However, my code is going sideways.
My button is created with the line below. I've set the variable j to be 1 earlier on in the code, just because I wanted to be able to do two things with CallBack and so I wanted some way to indicate the the button has been clicked (I am, however, certainly not attached to this as a method). When the user clicks the button, I would really like for 1) the loop for new impoints to stop and 2) the image to close.
uicontrol('Style','pushbutton','Position',[80 0 70 20],'String','Done','CallBack','j=0;');
My loop for impoints (with extra stuff that I don't think is relevant removed) is as follows:
for k = 1:2*mboxes*nboxes
if j == 0
close(gcf);
break;
elseif j == 1
fprintf('At line 56, j is %d and k is %d\n', j, k)
h = impoint;
setColor(h,'k');
location = h.getPosition;
end
clear h;
end
At the moment, my problems are two-fold. Really, three-fold, but I can grudgingly live with the third problem. Problem 1, which is most concerning to me, is that I have to click the button just before I want to finish, which is to say that I click the button and then set down another point before the window will close. (In other words, it's going through the loop one time more than I want and I'm not sure how to tell it not to do that.) Problem 2, which I'm sure should tell me something about how it's looping, is that the impoints aren't being deleted as I go along (though h does seem to be deleted at the end). Problem 3, which is aesthetic but really annoys me, is that I keep getting a blue impoint in the upper left corner (0,0) of my image before I click where I actually want.
Any help would be much, much appreciated. :)
I'm not sure about that, but I can only answer here not comment.... so what I guess:
Adressing your problem 2:
your h isn't deleted completly, try to use delete(h) instead of clear. This should also make your problem 3
Adressing your problem 1:
impoint get's your click position whereever you click I assume, even if you click on your button, so the two functions (get the impoint AND the click event) might overlap and give you that error. Maybe a look at the setPositionConstraintFcn can help you with this (enabling the click only for the area you want it to work).

How to click 2 screen regions at once and how to click without moving pointer in autohotkey

So how to click 2 screen regions at the same time or very fast one after another by using a single hotkey. The intent is to cover clicking on an object that can appear in 2 random areas of the screen by using a single key.
As an example I have tried using
a::click 735, 626 send, 750, 204 send, but it creates a loop for a few seconds, where the mouse is unresponsive and hovers in those areas, and using 2 separate hotkeys takes more time than i would wish.
I would also like to know if it is possible to issue a click command via a hotkey but not move the mouse pointer at all. I would like to set a hotkey that pressed will issue a left click command on a determined area of the screen but not move the mouse pointer in order to do so.
You definitely need to take a look at the help docs or FAQ again as well as some other examples to understand basic syntax. It is only one command per line. Here is an example of code that will get you going.
CoordMode, Mouse, Screen
SetDefaultMouseSpeed, 0 ; Sets default mouse speed to maximum
a::
MouseGetPos, X, Y ; Stores current mouse position
Click 735, 626
Click 735, 500
MouseMove, % X, % Y ; Moves mouse back to original position
Return
For the second question about issuing a click command without using the pointer, I suggest you look at the ControlClick documentation here: http://www.autohotkey.com/docs/commands/ControlClick.htm

Autohotkey - ImageSearch

I m trying to test a GUI by comparing my current screen with an image of the required screen and seeing if they match. I m using ImageSearch of AutoHotKey for this.
CoordMode, Pixel
ImageSearch,x,y,0,0,A_ScreenWidth,A_ScreenHeight,*255 C:\Documents and Settings\XYZ\Desktop\AutoHotkey\help window.bmp
if ErrorLevel=1
Msgbox 0,Fail,Fail
if ErrorLevel=0
{
MouseClick, left, 50, 191
Sleep, 100
}
I keep getting an ErrorLevel =1. Any suggestions on how I can resolve this.
Thanks
The *255 is messing you up. This basically nullifies the image search, since everything on the screen will match the image. Try something lower. It's unlikely you should need higher than *100
Also, as a general tip, try using the smallest possible version of the image you're searching for.