Autohotkey pixelsearch including mouse - autohotkey

I have done a decent amount of researching and I apologize in advance if I have missed the answer to this question in the documentation or forums somewhere.
I would like to do a pixel search of several area's and have a script react to the area when my mouse moves over that area, my idea was to use a custom cursor with a pixel shade not found in the application I'm manipulating, but Pixelsearch nor PixelgetColor seem to recognize the mouse, am I doing something wrong or did I miss something, or is this simply not possible?
Loop
{
PixelSearch, pxcolor, pxcolor1, 872, 367, 893, 394, 0x5F415F, 3, Fast
sleep, 200
if pxcolor < 0
click left
sleep, 200
}
So basically, the script is doing a constant check for a pixel of that shade in that area, and when my mouse moves over that area (the cursor being what contains the pixel shade), the script reacts.
What happens instead is it only sees the pixels of the window, and takes no notice of my cursor.

Trie something like this out, may do what you need
#Persistent
SetTimer, WatchCursor, 100
return
WatchCursor:
MouseGetPos, xpos, ypos, id, control
if Xpos between 600 and 800
{
if ypos between 400 and 600
ToolTip, React Here
}
else if Xpos between 200 and 400
{
if ypos between 100 and 300
ToolTip, Also React Here
}
else
ToolTip
return
Hope it helps

Related

How to stop script as soon as active window is no longer the desired window

I'm scripting some pre-determined Clicks and Sends at a specific window.
Sometimes a click will not end up at the desired location, it may click on a different window and now all subsequent inputs from my script will be sent to the wrong window/location.
Here is the executing part of the code which I can't seem to make 100% consistent.
CoordMode, Mouse, Window
SetTitleMatchMode, 2
<!p::
Click, 60, 270
Send, %dp%{Tab}{Tab}{Tab}{Tab}%e1%{Tab}^a ; Plate thickness and layout
Send, %PLh% ; Plate Height
Click, 60, 130
Sleep 100
Click, 263, 45
Sleep 20
Click, 263, 45
Sleep 20
Click, 370, 48
Sleep 100
Click, %Mx%, %My% ; Bolt Diameters (M16: 40, 135) (M20: 40, 150) (M24: 40, 170) (M27: 40, 190) (M30: 40, 210)
Sleep 50
Click, 60, 160
Send, {Tab}{Tab}{Tab}%w1%{Tab}{Tab}^a ; Hor Bolt center distance
Sleep 50
Send, 0{Tab}^a ; Edge distance
Send, 0 ; Edge distance
Sleep 100
Click, 60, 190
Sleep 100
Send, {Tab}{Tab}%e3% ; Vert interm distance
Send, {Tab}{Tab}{Tab}{Tab}{Tab}%e2% ; vert outside bolt dist
Click, 60, 295
Sleep 100
Send, {Tab}%Stiff%{Tab}{Tab}{Tab}%Stiff% ; Stiffener thickness
Sleep 100
Click, 60, 320
Sleep 100
Send, %Weld%{Tab}{Tab}{Tab}%Weld%{Tab}{Tab}%Weld%{Tab}{Tab}%Weld%{Tab}{Tab}%Weld% ; Weld thickness
Return
If any of the clicks in this section of code result in activating an undesired window then I would like my script to stop and give a warning.
I could insert an If Winactive statement for every click, but that feels very inelegant to me, perhaps there is a better solution?
(I could also ask how to make this script more consistent which I've already tried to do by inserting Sleep commands, but that's a different question. The main culprit seems to be clicking drop-down boxes, but it's tough to determine that since I can't debug AHK code by running line-by-line)
Thanks in advance
So kindly enough Yane pointed me in the direction of "Controlsend" and "Controlclick" which covers the problem I was having.
Instead of using, for example:
Click, 60, 300
One can force a click in a specific window like this:
ControlClick, x60 y300, MyDesiredWindow'sTitle
Furthermore, to fix my specific case of a Click on a dropbox throwing off the rest of the script, the following can be used:
ControlClick, ComboBox1, MyDesiredWindow'sTitle
This will Click a specific control in a specific window. (use Window Spy to identify windows and controls)
I guess my question is largely irrelevant when properly making use of ControlSend and other AHK commands and practices.
It seems to me that it's possible to directly answer the question in the title and, although my answer doesn't really do that, I will accept my own answer when it becomes possible for me to do so because it did solve my problem.

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.

Autohotkey Mouse Click Every 45 Minutes

I'm trying to make autohotkey click a certain screen region, every 45 minutes. I've come up with this, but it seems not to respond correctly.
Can anyone offer suggestions?
Loop,99
{
MouseClick, left, 392, 735
Sleep 2700000
}
Return
When you say doesn't respond correctly, can you be more specific? Is your loop not working, is the timer giving you issues or is the mouseclick not working. In some browsers, I've noticed that you might need to play around with mouseclicking (there are various ways to simulate a mouseclick [up to sending raw code] and there are timers to set the click time).
If you want the loop to indeed only run 99 times, you might need to add a counter in my example, but your objective cab be done with the settimer command.
SetTimer, MyMouseClick, 2700000 ; Run every 2700 seconds
Return
MyMouseClick:
MouseClick, left, 392, 735
Return
Alternative with 99 limit.
MyCounter := 0
SetTimer, MyMouseClick, 2700000 ; Run every 2700 seconds
Return
MyMouseClick:
MyCounter++
MouseClick, left, 392, 735
If (MyCounter = 100)
SetTimer, MyMouseClick, Off
Return
If you want to click a fixed screen coordiate, than make sure you are using CoordMode, Mouse, Screen. A script starts with a default of Relative.
CoordMode
CoordMode, Mouse, Screen
Loop, 99
{
MouseClick, left, 42, 34
Sleep 2000
}
Return
F12::ExitApp

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.