Auto HotKey, Toggle: Hold Shift, Click and release LButton every second - autohotkey

I'm trying to make an AutoHotkey script that holds Shift, and while it's holding it I need the mouse to click and release every second. This is what I have come up with so far.
Home::
KeyDown := !KeyDown
If KeyDown
SendInput {Shift down}, Click, Sleep 2000
Else
SendInput {Shift up}
Return

This loop after a certain amount of time behavior is best implemented with a SetTimer function invoking a Subroutine.
Additionally, since your script holds down the Shift key, you would need to also have the hotkey be invoked whenever Shift+Home is pressed as well, so that it can be turned off.
Final Code:
Home::
+Home:: ;Alternative hotkey definition that invokes on Shift+Home
KeyDown := !KeyDown
if (KeyDown){
SendInput {Shift down}
gosub, clickSubroutine ;To trigger the first click immediately
SetTimer, clickSubroutine, 1000 ;To trigger clicks after every 1000 ms (1 second)
}
else{
SendInput {Shift up}
SetTimer, clickSubroutine, Off ;Turn off the clickSubroutine Loop
}
Return
clickSubroutine:
Click
return

Related

autohotkey: bind <Enter> to <Control> while retaining certain behaviors

Is there a way to bind the <ENTER> key to <CONTROL> key, while retaining certain behavior of <ENTER> key?
The behavior I'm trying to achieve is as follows:
Pressing <ENTER> and "a" results in <CONTROL> + "a"
Pressing <ENTER> and "1" results in <CONTROL> + "1"
Pressing <ENTER> alone results in <ENTER>
Pressing <ENTER> and <ALT> results in <ENTER> + <ALT>
Shouldn't be too tough, I've not had time to test it but at least it's a starting point.
!enter:: send {alt down} {enter} {alt up}
enter down::
settimer, timer, on
hotkey, enter down, off
return
enter up::
settimer, timer, off
send, {ctrl up}
if a_timesincelasthotkey >= 750
send, {enter}
return
timer:
settimer, timer, off
send {ctrl down}
while getkeystate( "enter", "p" )
sleep, 1
send, {ctrl up}
return

Change a key function for x amount of time?

So thanks to this user i have got this working code, but i want to further tweak it if its posibble. :D
Here is the code:
global s:=0, c:=0, t:=1500, t2:=380
*lbutton::
send % Seqkeys("5","6")
KeyWait, lbutton
If (A_TickCount-s < t2)
c := 0
Send, 7
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]
}
What i want to implement is that if i hit the right mouse button (Rbutton), the original lbutton seqkeys code changes to this code for 1 second
*lbutton::
send, 8
KeyWait, lbutton
Send, 7
return
than when the 1 sec is over the code is revert back to the original seqkeys state.
I got this code sample but its not working properly for several reasons, when i hit the Rbutton it does override the original Seqkeys function, but it never resets back to the seqkeys one. I put it here maybe it helps
*rbutton::
toggle:=true
return
#If Toggle
*lbutton::
send, 8
KeyWait, lbutton
Send, 7
return
toggle:=false
Return
#If
Thx again! :)
The reason why it never reset back to Seqkeys(params*) after toggle is that toggle:=false is outside the toggled lbutton hotkey.
Putting it inside toggle lbutton hotkey before the return statement fixes the issue.
#If Toggle
*lbutton::
send, 8
KeyWait, lbutton
Send, 7
toggle:=false
return

Run a AHK function or statement only once, after any member of set of keys is pressed and held down

So in this case I am asking AHK to press shift twice with the following functions.
ShiftPress(delay){
send {Shift Down}
Sleep, delay
send {Shift Up}
Sleep, delay
}
ShiftPressTwice(delay){
ShiftPress(delay)
ShiftPress(delay)
}
For this set of keys (Not sure if this is the best way to iterate over a set of keys, only using examples I have found online)
w::
a::
s::
d::
1::
2::
3::
4::
5::
Space::
ShiftPressTwice(10)
while GetKeyState("Space")
{
Sleep, 10
}
Return
My thought is the above code is bit like switch case fall through, then it should call my function ShiftPressTwice(delay) one time, then hit the GetKeyState(key) loop and sleep then bail. What happens is this seems to run in a endless loop. Please let me know if you have any questions.
w::
a::
s::
d::
1::
2::
3::
4::
5::
Space::
ShiftPressTwice(10)
KeyWait %A_ThisHotkey%
Return

AHK - How to hold a macro while Physical Key depressed

What I want to do is this:
Numpad3::
if(not GetKeyState("Shift" , "P") and not GetKeyState("RButton" , "P"))
{
SendInput {Shift down}
Sleep, 33
Click down right
}
Return
Numpad3 Up::
Sleep, 100
Click up right
Sleep, 33
SendInput {Shift up}
Return
But for some reason it isn't canceling when I let the button up. :(
I would suggest to use Send {RButton Down} (or Up) to send the right mouse click, instead of Click up right.
Also, you don't want to be sending random Sleep's if they are not really necessary, as it creates lag and makes the script inelegant and potentially unreadable.
Here is code which sends Control instead of RButton but it's only so I can test it within Notepad++.
Just replace Control with RButton and have a go:
*NumpadPgDn::
*Numpad3::
Send {Shift Down}{Control Down}
return
*NumpadPgDn Up::
*Numpad3 Up::
Send {Shift Up}{Control Up}
return

Autohotkey: Can't figure out why this is pushing Shift along with the rest of the code

I am trying to make a macro that will repeat hitting O and M as long as i have my side mouse button held down, but all of a sudden now it is also hitting shift. Any idea why or how to fix it?
delaybetweenfkeys:=0
fkeydowndelay:=5
XButton1::
Down := True
Send, {O Down}{m Down}
Loop
{
Send, {O Down}{m Down}
Sleep, 5
Send, {O Up}{m Up}
If !Down
Break
}
Send, {O Up}{m Up}
Return
XButton1 Up::Down := False
You're telling it to send a capital 'O', and to achieve that, it sends Shift+o. So if you have some other key being pressed in the meantime, it will get shifted as well.