AHK: GetKeyState, can't send 2 commands - autohotkey

Basically what I want to do is: While I hold down the "a"-key the script automatically holds and releases the "a"-key over and over. It also has to press or hold/release the "h"-key. It causes me problems when I try to add the "h"-key (it spams the "h"-key whenever I activate the script instead of waiting for an "a"-press).
#Persistent
SetTimer, Clicking
F2::ExitApp
Clicking:
a::
if (GetKeyState("a", "P"))
Send {a down}
Send {h down}
Sleep 100
Send {h up}
Send {a up}
Sleep 475
Return
a up:: Send {a up}
Any help would be greatly appreciated! :-)

You need braces around your if block:
if (GetKeyState("a", "P"))
{
Send {a down}
Send {h down}
...
}

Related

Why are a and d not getting pressed the same amount?

I need a macro to press "a" then "d" shortly after and i need them to be pressed the same amount but it isn't working, how can i fix this?
Loop {
Send {s down}
Click, right
Sleep, 1
Send {d up}
Send {a down}
Click, R
Send {s down}
Click, right
Sleep, 1
Send {a up}
Send {d down}
Click, R
}
Can you clarify what the hole script should do?
If you just want to press "a" and afterwards "d", don't use the "up" and "down" parameters.
1::
Loop{
send {a}
send {d}
}
If you need the buttons to be pressed an precise amount of time, work with some sleeps.
1::
Loop{
send {a down}
sleep x
send {a up}
send {d down}
sleep x
send {d up}
}

Fixing Keyboard shortcut send in Auto Hot Key

Hi this is a super easy question but I was hoping someone could help me solve two AutoHotKey questions.
I am trying to get the keys Cntrl, J and I to be a keyboard shortcut that sends alt,h,v, and f.
Thus far I have tried these two ways of typing it
^&j&i::Send, !&h&v&f
^ji::Send, !hvf
as well as each of those without the comma after send.
I am also looking to send these keys on a very small delay, such as 5ms between each key
I was thinking of using something like this
^&j&i::
{
Send, {! down}
sleep 5
Send, {h down}
sleep 5
Send, {v down}
sleep 5
Send< {f down}
}
but of course, that is not working either. Any help is appreciated
Refer to https://www.autohotkey.com/docs/Hotkeys.htm#combo
Combinations of three or more keys are not supported. With this in mind we need to check the key state of the control key before defining the hotkey.
A few other things to note: SendInput is the ideal send method, and you likely want those keys back into an up state which I've included in my example.
#if GetKeyState("LControl", "P")
{
j & i::
{
SendInput {Alt down}
sleep 5
SendInput {h down}
sleep 5
SendInput {v down}
sleep 5
SendInput {f down}
sleep 5
SendInput {Alt Up}
sleep 5
SendInput {h Up}
sleep 5
SendInput {v Up}
sleep 5
SendInput {f Up}
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

AHK Disable Script A when Script B is Executed

hi again my script is almost complete but there is problem in executing hotkeys
Problem : when i hit Alt + Space it is conflicting with Space .. they are overlaping each other or executing both hotkey which makes custom modifier keys unstable or not working as intented
here is the code:
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
#if, GetKeyState("MButton")
Lbutton::
RButton::
return
#if
i want to add a rule if alt + space keycombo is held down this hotkey will not work
meaning i want to disable Script A if Script B is executed
Script A ::
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
Script B ::
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
thank you in advance
Wrap the space:: part in #If, !GetKeyState("Alt")
!space::
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
return
#if, !GetKeyState("Alt")
space::
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
return
#if, GetKeyState("MButton")
Lbutton::
RButton::
return
#if
space::
Hotkey_Alt_Space = 0 ; disabled
send {shift down}{MButton down}
KeyWait, space
send {shift up}{Mbutton up}
Hotkey_Alt_Space = 1
return
!space::
If (Hotkey_Alt_Space != 0) ; enabled
{
send {Mbutton down}
KeyWait, space
keywait, alt
send {Mbutton Up}
}
return
i was help by someone at AHK forum thank you for time the problem is solve i am able to customize my rotate and pan navigation at sketchup

Autohotkey, Step by Step Execution

This may be a very simple code but I am not able to find how to do it.
I have this
Send, Hi
Send, How Are you
Send, I am Fine
I want to do it like this
Hi How Are you
....
Right now with the below code
KeyWait, Capslock
Send, Hi
KeyWait, Capslock
Send, How Are you
KeyWait, Capslock
Send, I am Fine
I get
HiHow Are YOuI Am Fine as soon as I press Capslock.
I want it to wait to execute the next command. THanks for your help.
KeyWait, Capslock
Send {Capslock} ; Tap it again to reset it and force it to be released
; or Send {Capslock Up} to force it to be released
; or SetCapslockState Off to disable it completley
Send, Hi KeyWait, Capslock{Enter}
Send, How Are you KeyWait, Capslock{Enter}
Send, I am Fine{Enter}
If you want it in a hotkey, you could do something like this.
~$CapsLock::
Send {CapsLock Up}
Send, Hi {Enter}
KeyWait, Capslock, D
Send {CapsLock Up}
Send, How Are you{Enter}
KeyWait, Capslock
Send {CapsLock Up}
Send, I am Fine{Enter}
return
(It's glitching on my computer, but it may be because I'm on a virtual machine.)
SetCapslockState
Sorry if it is too late,but i did it anyways for everyone searching the solution for it,i assume you want to change it every time u press capslock to be different text:
CapsLock::
CapsLock0:
{
SendRaw Hi
Sleep 500
KeyWait, CapsLock, D
{
Goto CapsLock1
}
}
Return
CapsLock1:
{
SendRaw How Are you
Sleep 500
KeyWait, CapsLock, D
{
Goto CapsLock2
}
}
Return
CapsLock2:
{
SendRaw I am Fine
Sleep 500
KeyWait, CapsLock, D
{
Goto CapsLock0
}
}
Return
Explaination for Sleep,it is used because if you would press CapsLock without it then 2 of the command blocks would be executed,it is especially needed.
How about this...
Capslock::
Send, Hi{Enter}
Sleep, 400 ; sleep briefly to allow the CapsLock key to be released
KeyWait, Capslock, D
Send, How Are you?{Enter}
Sleep, 400
KeyWait, Capslock, D
Send, I am fine Thank you.{Enter}
Return
How about this...
Capslock::
Send, Hi{Enter}
KeyWait, Capslock, U
KeyWait, Capslock, D
Send, How Are you?{Enter}
KeyWait, Capslock, U
KeyWait, Capslock, D
Send, I am fine Thank you.{Enter}
Return