combining hotkeys - autohotkey

I'm trying to make an autoclicker in autohotkey but can't get it to work.
I have some knowledge about autohotkey but it is not very much:
<^LButton::
Loop
{
SetMouseDelay 0.001
Click
If(GetKeyState("LButton","P")=0)
Break
}
It works with <^LButton as hotkey, but not <^nLButton.
Therefore I need help with hotkey-combinations.
I get the errorcode:
Line Text: <^nLButtonSuspend
Error: This line does not contain a recognized action.

If you want to combinate Three keys as a Hotkey.
Click the Keys : [Ctrl] + [n] + [Lbutton] = Do a Action.
You can Try this:
example1.ahk
;#notrayicon
#SingleInstance force
^n::
GetKeyState, state, Lbutton
if state = D
{
Loop
{
send a
;SetMouseDelay 0.001
;Click
If(GetKeyState("LButton","P")=0)
Break
}
} else {
send b ;this codeline is only so that you can test it out in notepad. - you can remove this
}
Return
esc::exitapp
note : It is not perfect but the answer is close to your Question.

Related

AHK v2 mouse clicking loop

global toggleVar := false
>^j::
{
global toggleVar :=! toggleVar
}
if (WinActive("Warframe") and toggleVar = true)
{
while (GetKeyState("LButton"))
{
Click
Sleep 250
}
}
I am absolute noob in autohotkey, installed it today, also got scared by a bunch of viruses. Anyways, I wanted to have a toggle variable and when I'm in a game I want to hold down LMB and it will continue clicking for me. But it does nothing and I have no idea why.
#HotIf WinActive("Warframe")
>^j::
{
static toggle := 0
HotIf 'WinActive("Warframe")' ; change the hotkey context for Hotkey function
Hotkey "LButton", SpamClick, (toggle := !toggle) ? "On" : "Off" ; enable or disable lbutton hotkey
SpamClick(ThisHotkey) {
while GetKeyState("LButton", "P") {
Click
Sleep 250
}
}
}
#HotIf
Apparently this is how it's supposed to be done, it worked for me. Thanks to "plankoe" from reddit.

Autohotkey Return to regular function of Spacebar after mapping

i am trying to be able to toggle between different functions mapped to the spacebar
mapping spacebar isnt difficult, but how the hell do i get the "regular" function of spacebar back ?
Space::Space isnt working XD
BackSpace::tog()
tog()
{
static togstate = 0
if (togstate = 1)
{
ToolTip, Spacebar Normal
SetTimer, RemoveToolTip, 1500
Space::
togstate = 0
}
else
{
ToolTip, Spacebar Alternativ
SetTimer, RemoveToolTip, 1500
Space::
{
SetKeyDelay,5, 10
Send, 2345
}
return
togstate = 1
}
}
Ordinary hotkey bindings are more like declarations than commands or functions. So, they need to be on the global level.
You just need to use the Hotkey command, either inside or outside of functions.
Example:
Hotkey Space, funcA
Hotkey Space, funcB
Hotkey Space, Off
funcA() {
...
}
funcB() {
...
}

Autohotkey: Ctrl + 1 mapping

I want to remap mouse click to a button depend on a state of Numlock. If Numlock is 'ON' then I want the normal behavior else map to mouse click. The script I created below works fine but I have trouble remapping CTRL+1.
SHIFT+1 will result in '!' so it is simple to do but I don't know what's the behavior for CTRL+1 is. The current script has the dummy "Send, {^1}" but that is not the real behavior.
I appreciate any suggestion.
*The Keywait is for simulating holding the mouse button and the script is enable/disabled base on Numlock state.
$1::
if GetKeyState("NumLock","T")
Send, {1}
else
{
Click down,
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
Send, {!}
else
{
Click down,
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
Send, {^1}
else
{
Click down,
KeyWait 1
Click up
}
Return
The following should do what you've described, with some cleanup to the code itself. I also recommend reading up on the various Send modes, as SendInput is superior in just about every way possible.
$1::
if GetKeyState("NumLock","T")
SendInput, 1
else
{
Click down
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
SendInput, {!}
else
{
Click down
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
SendInput, ^1
else
{
Click down
KeyWait 1
Click up
}
Return

Suspend AHK script

I'm writing a script for AHK which automate few things in my MMORPG game.
I want to perform 2 different automation when F2 or F3 is pressed.
Sometimes this script is with interaction with another action from keyboard/mouse so I need to suspend script when one of the following keys is pressed: 2,3,4,5,E,R
But when I press 1 the script need to be unsuspended.
I was trying many different options but I can't write it. I can't even google anything similiar.
My code looks like that:
key_a:="F2"
key_b:="F3"
loop {
sleep 1
if GetKeyState(key_a) {
a:=true
b:=false
}
if GetKeyState(key_b) {
a:=false
b:=true
}
if a {
MsgBox, Do something
}
if b {
MsgBox, Do somethiung else
}
}
This script language is bit strange for me.
Can you help me.
Thanks
Try:
key_a:="F2"
key_b:="F3"
SetTimer, keyStates, 100
KeyStates: ; SubRoutine
if GetKeyState(key_a, "P") {
a:=true
b:=false
}
if GetKeyState(key_b, "P") {
a:=false
b:=true
}
if a {
ToolTip, F2 is doing something
}
if b {
ToolTip, F3 is Doing Something!
}
return
2::
3::
4::
5::
E::
R::SetTimer, keyStates, Off
1::SetTimer, keyStates, on

How to have one key toggle between two functions using AHK

How would I go about creating a hotkey in AHK that runs one function the first time it is pressed and another one the second time it is pressed. I'm trying to emulate an on/off scenario.
Can it be done and if so how?
Something like this pseudo code is what I'm looking for:
#space::toggleit()
toggleit()
{
if (last time it was pressed, functionA was run)
run functionB
else
run functionA
}
I'm using AHK version 1.1.19.01
Try using AutoHotkey's hotkey-command:
hotkey, #space, functionA
return
functionA:
hotkey, #space, functionB
msgbox, A
return
functionB:
hotkey, #space, functionA
msgbox, B
return
If you'd want to toggle only between functionA and "do nothing", you can use the following:
hotkey, #space, functionA, toggle
return
functionA:
msgbox, A
return
I found a solution. Putting it here for other's benefit:
#space::tog()
tog()
{
static togstate = 0
if (togstate = 1)
{
msgbox ON
togstate = 0
}
else
{
msgbox OFF
togstate = 1
}
}
An easy way is to use a variable:
setting := false
toggleit()
{
if setting
run functionB
else
run functionA
setting := !setting
}