I would like to drag window using right click with title bar just like left click. Is it possible do that with AutoHotkey?
Background : I use Dell Display Manager which lets me arrange my windows in pre-defined grid. I can do this directly dragging or Shift+ Drag. Both options are sub optimal. Direct dragging just forces unwanted resize. Shift and Drag requires a key and mouse. I am wondering if I can drag using right click. I use application called RBTray to minimize to tray using right click. So, I know we can definitely add something like. I am looking something in AutoHotkey as that's much easier to code than C++.
This is probably what you're looking for: https://www.autohotkey.com/docs/scripts/index.htm#EasyWindowDrag
Below is code adapted to right click:
~RButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 0 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, RButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, Off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, Off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return
Related
I am trying to figure out how to have an AutoHotKey script save different coordinates through MouseGetPos on different hotkeys at the same time, without one overwriting the other.
I want to make a loop performing some sequence of events. Say at one point I want it to execute the first coordinate that I saved before or during the loop (but before the action), and then I want the script to execute the other coordinate at a later point in the loop.
I want the coordinates to be able to be preset (instead of pressing Hotkey1 before the action of hotkey1 and consequently hotkey2 after hotkey1 to ensure one is not overwritten).
An example of this would be:
If one hotkey saves one coordinate:
hotkey1::
MouseGetPos, posx, posy,
// If inserted into a loop, it would be:
MouseMove, %posx%, %posy%,
One hotkey saves another coordinate:
hotkey2::
MouseGetPos, posx1, posy1,
// In loop:
MouseMove, %posx1%, %posy1%,
If inputted into a random loop
#SingleInstance Force
SendMode Input
#MaxThreadsPerHotkey, 2
#NoEnv
#Persistent
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 3
SetMouseDelay, -1
Process, Priority, , H
SetKeyDelay, -1, -1
SetDefaultMouseSpeed, 0
SetKeyDelay, 0, 10, Play
SetMouseDelay, 10, Play
CoordMode, Mouse, Screen
hotkey1::
MouseGetPos, posx, posy,
return
hotkey2::
MouseGetPos, posx1, posy1,
return
Toggle=0
f::
Toggle := !Toggle
Loop
{
If Toggle
{
Send {a}
sleep 100
MouseMove, %posx%, %posy%, // Say I want it to move to bottom left corner
Send {LButton}
sleep 100
If !Toggle
Break
MouseMove, %posx1%, %posy1%, // Say this coordinate would be top-right corner
Send {LButton}
sleep 100
Send {c}
}
}
return
q::ExitApp
If I trigger hotkey1 and hotkey2 in that order, hotkey1 would get saved then overwritten by hotkey2, making hotkey1 the same coordinate as hotkey2. I would want 2 separately saved coordinates.
Do I do that by having one script trigger another script or can this be done in a single script?
I'm trying to make a script that will press the RButton after holding the LButton for a specific amount of time and ignore the left click. I don't know how to go about this.
Pseudo code:
timer = 0;
while(LButton down){
add 1 to timer?
if(timer==100){
Send {RButton}
ignore LButton
reset timer
}
}
Use A_TickCount as a quick and easy way of measuring the passing of time.
(TESTED)
LButton::
StartTime := A_Tickcount
WaitTimeInMilliSeconds = 1000
tooltip trying
while(StartTime+WaitTimeInMilliSeconds > A_Tickcount)
{
if(!GetKeyState("LButton","P"))
{
click ;send the click anyway if it's not held.
return
}
}
tooltip this happens after 1000 milli second of continuously holding left mouse button
return
If you put this inside a left mouse button hotkey it will reset itself automatically. If you want it looping all the time, you can put the entire thing in an endless loop and reset the starttime instead of return
I want to remap left click of my mouse to mouse wheel up when a certain keyboard key(let's say SHIFT) is hold. It should go back to normal after the key is released.
Here is my current script:
Loop
{
If(GetKeyState("Shift", "P"))
LButton::WheelUp
If(GetKeyState("Shift", "P")=0)
Hotkey, *LButton, off
}
I have two problems with it:
It remaps my left button without any pressed key.
I want it to continuously do "wheel up" as long as the SHIFT key is down and the left mouse button is pressed.
The following will send WheelUp every 0.5 seconds as long as SHIFT and left mouse button are pressed:
+LButton::
sendWheelUp := true
while (sendWheelUp) {
send, {WheelUp}
sleep 500
}
return
+LButton up::sendWheelUp := false
You can adjust sleep time to increase or decrease the frequency.
I'm having trouble to control click i'm trying to simulate control click without moving mouse, but i always get error when i run is there something wrong in my code.
PixelSearch, X, Y, 0, 0, 1292, 747, 0x00FF00, 0, fast
if(ErrorLevel=0)
sleep, 100
ControlClick, %X% %Y%, form1, Left, 1
There are a few things you've missed.
First, If Statements only execute the line beneath them. If you have more than 1 line of code, you have to put it in curly braces. It's called A Block/Blocking (Multiple Lines of Code Inside Braces)
Second, your ControlClick syntax is wrong. If you're passing coordinates, you have to put x and y in front of them so controlclick knows they're coords.
Incorrect:
ControlClick, %X% %Y%
Correct:
ControlClick, x%X% x%Y%
Third, if you look at your code, you have Left where WinText is supposed to be.
Syntax for ControlClick:
ControlClick [, Control-or-Position, WinTitle, WinText , WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText]
You can't assume AHK knows Left is for the button. You have to tell it to skip that field by putting a comma there to indicate the field is blank. That way it knows to skip wintext and treat Left as the WhichButton field.
Incorrect:
ControlClick, %X% %Y%, form1, Left
Correct:
ControlClick, %X% %Y%, form1,, Left
Put it all together, and you have this:
PixelSearch, X, Y, 0, 0, 1292, 747, 0x00FF00, 0, fast
if (ErrorLevel = 0){
Sleep, 100
ControlClick, x%X% y%Y%, form1, , Left, 1
}
Let me know if that solves your problem.
Edit: Apparently this didn't fix your issue. I'm going to bet your controlclick and the info you're passing it are the problem.
Make sure you define CoordMode at the beginning of the script. You need to set it to fullscreen or relative.
Next, don't use a window's title for WinTitle unless there's a good reason to. Instead of form1, use something like ahk_exe chrome.exe. It's much more reliable.
#SingleInstance, Force
CoordMode, Pixel, Screen
return
F1::
PixelSearch, X, Y, 0, 0, 1292, 747, 0x00FF00, 0, fast
if (ErrorLevel = 0){
Sleep, 100
ControlClick, x%X% y%Y%, ahk_exe yourExeName.exe, , Left, 1
}
return
What program/site/game are you using this for?
I am struggling to make an AutoHotkey script, if anyone would help I would appreciate it.
the script im trying to make is: if I pressed F my mouse would move to the left as long as im pushing the F button from the current location I had my mouse on. This is what I have right now and it's not working.
Loop {
Sleep 10
MouseGetPos,x
if (MouseMove, -1000, 0, 100, R)
send {C down}
else if {C up}
break
}
return
Esc::ExitApp
Try this:
f::MouseMove -5, 0, 50, R
50 is the speed, and the R letter means that the offset is relative to the current cursor position. You don't need the loop, as the pressed key will generate subsequent events on its own.