Send RButton after holding LButton for time - autohotkey

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

Related

How to drag window using right click down with AutoHotKey?

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

How do I hold in a key from the start of a loop, until it finishes in AHK?

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.

Need to send mouse wheel up when SHIFT key is down and left mouse is clicked?

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.

Autohotkey loop sequence with idle reset

I cobbled the following together from various posts:
keys = 0,9,8,7
loop, parse, keys, `,
{
Key_%A_Index% := A_LoopField
KeyCount++
}
return
XButton1::
Rotation ++
Send % Key_%Rotation%
if Rotation = %KeyCount%
Rotation = 0
return
#Persistent
SetTimer, Check, 1000 ;check every second
return
Check:
If (A_TimeIdle >= 3000)
Rotation = 0
return
The idea being that I press my mouse4 button and it cycles through the keys and then goes back to start, however I also wanted a loop so that if I don't press the button for 3 seconds, it resets back to the start of the sequence. The key sequence works however the idle reset doesnt and I'm not sure where to go from here to debug it.
1- You must let the #Persistent SetTimer, Check, 1000 part before the first return.
2- A_TimeIdle is sensible to any input, even a simple mouse move (by user or by script) resets it to zero. If you want to get the Idle time of this single hotkey use A_TimeSinceThisHotkey instead:
Check:
if (A_TimeSinceThisHotkey >= 3000)
{
Rotation = 0
}
return

AutoHotkey push a button to move curser to the left

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.