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.
Related
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
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 Have a loop I am trying to get to work properly, so space is held throughout the entire looping period, and it doesnt have to be pressed within the loop to be activated.
I tried moving the space function outside of the loop, and release it after, but then it doesnt recognize the action at all.
toggle = 0
#MaxThreadsPerHotkey 20
!Z::
Toggle := !Toggle
While Toggle{
Loop, X
{
Send {Space down}
MouseMove, %X1%, %Y1%, 3,
MouseClick, L
Sleep Y
MouseMove, %X2%, %Y2%, 3
Sleep Y
MouseClick, L
Send {Space up}}
If !Toggle
Break
}
return
The result I want to happen is that for as long as that loop is running, spacebar is pressed down, from before the loop starts, and is released after the loop ends.
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.