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.
Related
Is it possible to move a window by for example 200 pixles downwards, or similar?
I have only found the WinMove command, but it requires an fixed location, instead of just moving the window a bit downwards for example.
So if I wanted to move the calc downwards a bit in the below example, how would I go about doing that?
Run, calc.exe
WinWait, Calculator
WinMove, xxxx?
Thanks!
What you need in this case, is the WinGetPos command.
Example:
; Press F1 to move the Calculator window 10 pixel downwards:
F1::
If !WinExist("Calculator") ; "!" means "NOT" in this case
Run, calc.exe
WinWait, Calculator
WinGetPos, X, Y, Width, Height, Calculator
WinMove, Calculator, , X, Y+10
return
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?
I have a simple Autohotkey script that I want to use to determine if the mouse was clicked inside a window. I want the function to fail if the click was on the title bar or on the scroll bars of the window. My script looks like this:
LButton::
WinGetPos, X, Y, Width, Height, A
MouseGetPos, x,y
Rightmargin := Width - 50
Topmargin := Y+25
if (x < Rightmargin and y > Topmargin)
MsgBox You're Inside
return
The problem is when I run this, it freezes up my machine. All the left mouse clicks are captured and do not get through to the system and for some reason the test case always fails (I never see the MsgBox).
Can you tell me what I am doing wrong?
Variables, Labelnames and so on are case-insensitive in AutoHotkey. So, with WinGetPos, X, Y and MouseGetPos, x,y, you are allocating these two variables twice, overwriting the window's position coordinates. So, for example, you might want to rename x to mouseX and y to mouseY.
Since you obviously want your mouse coordinates being measured by the current window, you should also include coordmode, mouse, relative before your hotkey assignments.
Finally, if you also want your Click to be send to the window, includ a tilde ~ before your Hotkey: ~LButton::.
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
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