I want to press a hotkey, "x", to trigger mouse clicks that alternate between two positions
If I press "x", the mouse should click at position A
If I press "x" again, the mouse should click at position B
If I press "x" again, the mouse should click at position A
and so on
Here is my pseudocode
global variable "i"
i = 0
x::
if (i % 2 = 0) {
Click position A
} else {
Click position B
}
i = i + 1
}
return
I don't know how to do this in Autohotkey, please help
here is an example
x::
if (toggle := !toggle)
MsgBox A
else
MsgBox B
return
Related
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]
}
I need a script that will left mouse click at a specific time of day. I found the following (see link) which is working but was wondering if there is now simpler code (this code is old ) that will do the same? I will be at the computer and can position the mouse so I won't need x, y coordinates. Any help will be greatly appreciated.
I copied the code from here:
https://autohotkey.com/board/topic/485-need-to-program-a-left-mouse-click-to-run-at-a-certain-time/
Code:
#persistent
TargetTime = 1800
StringLeft, TargetDateTime, A_Now, 8 ; Put just YYYYMMDD into the
variable.
TargetDateTime = %TargetDateTime%%TargetTime%
TimeUntilTarget = %TargetDateTime%
TimeUntilTarget -= %A_Now%, seconds
if TimeUntilTarget < 0
{
MsgBox The target time is already past!
return
}
TimeUntilTarget *= 1000 ; Convert to milliseconds.
TimeUntilTarget -= 1000
SetTimer, ClickTimer, %TimeUntilTarget%
return
ClickTimer:
SetTimer, ClickTimer, off ; i.e. do only one click
MouseClick, left
Okay so I wrote this script in AHK to press 2 on the first press of the mouse button and 3 on the second and so on, yet it doesnt work. Any ideas why ?
XButton1::Send, 1;
XButton2::
x:=1
if (x = 1){
Send, 2
x+=1
} else if (x = 2) {
Send, 3
x+=1
} else if (x = 3) {
Send, 4
x+=1
} else if (x = 4) {
Send, 5
x = x - 3
}
Everytime you press XButton2, you reset the value of x to 1....x:=1. So it will obviously only send 2. You need to set the value of x outside of XButton2. This will work:
x := 1
XButton2::
x += 1
SendInput, %x%
return
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.
Unity 5.3.4 Version
My problem is when I am moving my character with 2 keys (diagonal motion) and I change the scene the character will cease to move in that direction and only move in the direction of the last key I pressed.
Example : I am moving up left (I first press the left key and then up key). I then get transferred to another scene and (I am still holding down the up and left key) my character will end up only moving up until I let go of the left key and press it again.
void Update(){
// Get a -1, 0 or 1.
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
// Check what is actually being called.
print ("up : " + Input.GetKey("w"));
print ("down : " + Input.GetKey("s"));
print ("left : " + Input.GetKey("a"));
print ("right : " + Input.GetKey("d"));
}
Is there a setting I can check to make multiple keys transfer over or is this a bug in Unity because even though I am holding down the left key the print statement will show false for 'left'.