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
Related
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.
I mean detect it without pressing a hotkey that will call the lines of code that will check it if said window is active
Below example works fine but pressing 4 is required.
4::
if WinActive("*Untitled - Notepad ahk_exe notepad.exe")
{
MsgBox, Found Notepad
}
else
{
MsgBox, Did Not Find Notepad
}
Return
I have also tried this, but it just spams me with MsgBoxes.
Loop, 50
{
if WinActive("ahk_class #32770")
{
MsgBox, Found Notepad
}
else
{
MsgBox, Did Not Find Notepad
}
}
Thanks.
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.
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() {
...
}
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
}