Code: Select all
I am new to AHK and trying to create a program which allows auto clicking and other functions by detecting if a key is held down.
I have made the code work for a specific key (Extra mouse button 'XButton2') but am having trouble making it work for a variable key.
I need the code to use a function like bellow to determine the state of a key (EG: XButton2) which then will allow it to perform a defined task through another function (EG: RepeatSpamClick)
Code: Select all
*$~XButton2::
Checkstate(XButton2,RepeatSpamClick)
return
Code: Select all
RepeatSpamClick:
MouseClick, left,,, 1, 0, D
Sleep, 10
MouseClick, left,,, 1, 0, U
Sleep 100
return
Code: Select all
*$~XButton2::
GetKeyState, XButton2State, XButton2
if XButton2State = D
Loop
{
GetKeyState, XButton2State, XButton2
if XButton2State = U
break
RepeatRapidSpamL(XButton2_SpamL_Delay)
}
RepeatRapidSpamL(XButton2_SpamL_Delay)
{
MouseClick, left,,, 1, 0, D
Sleep, 10
MouseClick, left,,, 1, 0, U
Sleep %XButton2_SpamL_Delay%
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force
Gui, +AlwaysOnTop
Gui, Color, Black
Gui, Font, cWhite
Hotkey,*$~XButton2,off
Hotkey,*$~XButton1,off
;-------------------------------------------
Gui, Add, Text, , Which Hotkeys would you like to activate?`n
Gui, Add, Checkbox, vXButton1_SpamR_State x10 group gSubmit_XButton1_SpamR_Check, XButton1 Rapid Clicker
Gui, Add, Edit, vXButton1_SpamR_Delay cBlack x27 limit4 number Disabled gSubmit,Delay(ms) between clicks
Gui, Add, Checkbox, vXButton2_SpamL_State x10 group gSubmit_XButton2_SpamL_Check, XButton2 Rapid Clicker
Gui, Add, Edit, vXButton2_SpamL_Delay cBlack x27 limit4 number Disabled gSubmit,Delay(ms) between clicks
;~ Gui, Add,
Gui, Show, w225 h200 Center, Active Hotkeys
Gui, Submit, NoHide
return
;-------------------------------------------
Submit:
gui, Submit, NoHide
return
;Spam Left Click Active-------------------------------------------
Submit_XButton2_SpamL_Check:
gui, Submit, NoHide
If (XButton2_SpamL_State=1)
{
GuiControl,Enabled,XButton2_SpamL_Delay
Hotkey,*$~XButton2,on
}
Else
{
GuiControl,Disabled,XButton2_SpamL_Delay
Hotkey,*$~XButton2,off
}
return
;Spam Left Click Hotkey--------------------------------------
*$~XButton2::
GetKeyState, XButton2State, XButton2
if XButton2State = D
Loop
{
GetKeyState, XButton2State, XButton2
if XButton2State = U
break
RepeatRapidSpamL(XButton2_SpamL_Delay)
}
RepeatRapidSpamL(XButton2_SpamL_Delay)
{
MouseClick, left,,, 1, 0, D
Sleep, 10
MouseClick, left,,, 1, 0, U
Sleep %XButton2_SpamL_Delay%
}
;Spam Right Click Active-------------------------------------------
Submit_XButton1_SpamR_Check:
gui, Submit, NoHide
If (XButton1_SpamR_State=1)
{
GuiControl,Enabled,XButton1_SpamR_Delay
Hotkey,*$~XButton1,on
}
Else
{
GuiControl,Disabled,XButton1_SpamR_Delay
Hotkey,*$~XButton1,off
}
return
;SpamR Right Click Hotkey--------------------------------------
*$~XButton1::
GetKeyState, XButton1State, XButton1
if XButton1State = D
Loop
{
GetKeyState, XButton1State, XButton1
if XButton1State = U
break
RepeatRapidSpamR(XButton1_SpamR_Delay)
}
RepeatRapidSpamR(XButton1_SpamR_Delay)
{
MouseClick, right,,, 1, 0, D
Sleep, 10
MouseClick, right,,, 1, 0, U
Sleep %XButton1_SpamR_Delay%
}
;-------------------------------------------
return
^!+x::
ExitApp
This code was an attempt at detecting the state of a variable key activate by another key which outputted the correct values (1 when pressed and 0 when unpressed)
Code: Select all
Key := "XButton2"
Numpad0::
%Key%State := GetKeyState(Key,"p")
Msgbox, %XButton2State%
return
Code: Select all
Key := "XButton2"
*$~XButton2::
%Key%State := GetKeyState(Key,"p")
Msgbox, %XButton2State%
return