How to input (Holding LButton)? - autohotkey

I am trying to make (Holding down the left button for 1s) to make it do a right click. Here's what i got:
LButton::
MouseClick, right, , , 1, 0, D
Sleep 0
MouseClick, right, , , 1, 0, U
return
How to change the "LButton" input into "Hold LButton for 1 second"?

How about this...
LButton::
StartTime := A_TickCount ; Set the timer
KeyWait, LButton ; Wait for release of mousebutton
ElapsedTime := A_TickCount - StartTime ; Calculate elapsed time
if (ElapsedTime > 1000)
Click, Right ; when longer than 1000 ms
Click, Left ; when shorter than 1000 ms
return
The disadvantage is that you can't use the mouse for e.g. highlighting text anymore...

Here you go:
#Persistent
#SingleInstance Force
#NoEnv
SetBatchLines, -1
global timeDown = 0
SetTimer, checkLeftClick,25
checkLeftClick:
if( GetKeyState("LButton" , "P") )
{
timeDown += 25
}
else
{
timeDown = 0
}
if(timeDown > 1000)
{
MouseClick , left , , , , ,U
Click,Right
timeDown = 0
}
return

Related

Moving the cursor to a specified position as soon as it touches right edge of screen using autohotkey?

I have written code to change mouse position when it touches the left edge of screen
sysget, var_, monitorworkarea
gui, color, 0x000000
gui, +alwaysontop +toolwindow -caption
gui, show, w1 h%var_bottom% x0 y0, left_win
winset, transparent, 1, left_win
onmessage(0x200, "edge")
return
edge()
{
static countdown := 0
if (countdown = 0)
{
settimer, check, -100
countdown := 1
}
return
check:
{
mousegetpos, , , win
wingettitle, title, ahk_id %win%
if (title = "left_win")
{
MouseMove, 960, 300, 0
}
countdown := 0
}
return
}
but it doesn't work if I replace left with right for right edge of screen How do I fix this ?
Try this
#Persistent
SetTimer, check, -100
return
check(){
If edge("left")
{
MouseMove, 960, 300, 0
Send #x
}
else if edge("right")
{
MouseMove, 960, 300, 0
Run Notepad
}
; ...
SetTimer, check, -100
}
edge(pos){
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79
T := 10
CoordMode, Mouse, Screen
MouseGetPos, mX, mY
left := (mX < T)
top := (mY < T)
right := (mX > VirtualWidth - T)
bottom := (mY > VirtualHeight - T)
If (pos = "left")
return left
else if (pos = "top")
return top
else if (pos = "right")
return right
else if (pos = "bottom")
return bottom
}

How to reset a key sequence with a specific key?

So this sequence resets itself after 1.5 sec (t:=1500) which means if i dont hit the left mouse button for 1.5 sec it always sends A. Otherwise it sends the next letter after each click.
I want to further tweak this code with another function which is to be able to reset the sequence with right mouse button too. So if i hit RButton any time it should reset to A.
Thx.
global s:=0, c:=0, t:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
Seqkeys(params*) {
global s, c, t
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1
s := A_TickCount
return params[c]
}
Merely reset the current key index 'c', and the last clicked time 's':
*RButton::
c := 1
s := 0
return
I think your script would benefit with more meaningful variable names:
global lastClickedTime:=0, currentKeyIndex:=0, clickThreshold:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
*RButton::
currentKeyIndex := 1
clickThreshold := 0
return
Seqkeys(params*) {
global lastClickedTime, currentKeyIndex, clickThreshold
max := params.MaxIndex()
currentKeyIndex += 1
if((A_TickCount - lastClickedTime) <= clickThreshold && currentKeyIndex <= max) {
; Do nothing
} else {
currentKeyIndex := 1
}
lastClickedTime := A_TickCount
return params[currentKeyIndex]
}

Why won't my script run when attemping to make a toggle on and off key?

Im trying to make an autohotkey script that loops but only when the script is toggled on, how can i pull this off? this one just doesnt run and idk why
g::
Suspend
Pause
return
Count := 1
Loop {
if (Count = 1){
Send {s down}
Send {a down}
Send {d up}
Count := Count + 1
}else if (Count = 1000){
Send {a up}
Send {d down}
Count := Count + 1
}else if (Count = 2000){
Count := 1
}else{
Count := Count + 1
}
Sleep, 10
}
First of all, I'm not sure why you're using Suspend. Pause should be sufficient to do what you're looking for. Suspend suspends all hotkeys (except the g hotkey in this case because it's the first line in the hotkey), whereas Pause pauses the current thread. And second of all, you have your loop after the hotkey. The auto-execute section of any autohotkey script is only from the top to the first hotkey, so you need to put the loop first, then the hotkey. Here is the revised code:
Count := 1
Loop {
if (Count = 1){
Send {s down}
Send {a down}
Send {d up}
Count := Count + 1
}else if (Count = 1000){
Send {a up}
Send {d down}
Count := Count + 1
}else if (Count = 2000){
Count := 1
}else{
Count := Count + 1
}
Sleep, 10
}
g::
Pause
return

Detect F key press after holding right mouse button

I am trying to write a script that detects Right Mouse Click being held for at least 1.5 seconds and then the F key being pressed down while Right Mouse Click is still being held.
I tried the following:
Loop
{
Send, {F Down}
Sleep 2000
Send, {F Up}
sleep 1500
}
return
^F::Pause
I realized this is only a timer and does not detect which keys were pressed. How do I write a script that achieves functionality described above?
loop
{
Key := GetKeyState("rbutton")
while(Key = 0)
{
Key := GetKeyState("rbutton")
sleep,100
}
while(Key = 1)
{
sleep,100
loopnmb := A_Index
if(loopnmb = 8) ;;this number changes the length rbutton has to be pressed before F key activates
{
Key := GetKeyState("rbutton")
while(Key = 1)
{
Send, {F Down}
Key := GetKeyState("rbutton")
if(Key = 0)
{
Send, {F Up}
break
}
}
}
}
}
Timer is a little bit off so play around with it.

Double tap SHIFT key followed by a letter

I would like to be able to double tap a SHIFT key followed by a letter to activate an action. Can anyone help? It would be nice to be able to double tap either SHIFT key.
Something like??
<+<+ or >+>+ then d
do something
return
~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 500)
{
Double_SHIFT := true
Sleep, 2000
Double_SHIFT := false
}
return
; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
a:: MsgBox, This macro has not yet been enabled. Contact IT for suggestions.
b:: FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
SendInput %CurrentDateTime%
c:: MsgBox, This macro has not yet been enabled. Contact IT for suggestions.
return
~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 500)
{
Double_SHIFT := true
ToolTip, Double_SHIFT ; remove this line, if you don't want a tooltip displayed
Sleep, 2000
Double_SHIFT := false
ToolTip ; remove this line, if you don't want a tooltip displayed
}
return
; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
a:: MsgBox, Double_SHIFT + a
b:: MsgBox, Double_SHIFT + b
#If
Displays message box when shiftshiftd pressed
~LShift::ShiftPressed()
~RShift::ShiftPressed()
$d::DPressed()
ShiftPressed()
{
global t1,t2
t1 := t2
t2 := A_TickCount
}
DPressed()
{
global t1,t2
if (A_TickCount < t1 + 1000) && (A_TickCount < t2 + 1000)
MsgBox Shift Shift D Pressed
else
sendinput d
}