Autohotkey Mouse Click Every 45 Minutes - macros

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

Related

Autohotkey: WinMenuSelectItem not working on Figma

Hope someone can help me with this.
I am trying to use Autohotkey to automate some menu navigation within figma.
Point is that the "WinMenuSelectItem" function somehow doesn't work.
While searching for this, i found a script to detect any clicked menu item, and tell its position.
Turns out that none of the menu items, were detected.
it made me suspect that probably Figma's Windows app is just a disguised web browser, so i have to approach this differently.
A solution could be to create my shortcuts through mouse position, but i once i switch screens, all the positioning will be messed.
Can someone help me?
Thank you!
Edit: As request, im going to paste the code i have right now.
But is almost of no use, as now i am using mouse movement to click on menu items, and this solution is both slow (on performing time) and as soon as i change screen resolution, those coordinates render useless.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^!+f1:: ; Go to main component
SendEvent {Click 28 63}
sleep, 100 ;
SendEvent {Click 93 228}
sleep, 400 ;
SendEvent {Click 291 464}
sleep, 100 ;
SendEvent {Click 550, 463}
CoordMode, Mouse, Screen
MouseMove, (A_ScreenWidth // 2), (A_ScreenHeight // 2)
return
^!+f2:: ; Plugin Papa component
SendEvent {Click 28 63}
sleep, 100 ;
SendEvent {Click 93 338}
sleep, 400 ;
SendEvent {Click 296 535}
sleep, 100 ;
CoordMode, Mouse, Screen
MouseMove, (A_ScreenWidth // 2), (A_ScreenHeight // 2)
return
^!+f3:: ; Copy Prototype link
SendEvent {Click 2374 69}
sleep, 400 ;
SendEvent {Click 1109 506}
return

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.

SetKeyDelay for Mouse Wheel

I want to scroll a page 5 times, with a small delay after each scroll. But instead of this, the page is scrolled without delays. Why?
~+PgDn::
SetKeyDelay, 50
Send, {WheelUp 5}
Return
For mouse clicks, SetMouseDelay should be used, but apparently WheelUp and WheelDown don't count as clicks so it won't work for them.
Use a Sleep command and a Loop instead:
Loop, 5
{
Send, {WheelUp}
Sleep, 50
}
Consider wrapping this into a function for convenience.

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 pixelsearch including mouse

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