Help with Menu+Script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Help with Menu+Script

07 Apr 2018, 17:03

Hi, currently I'm trying to use the code below in order to have a menu in which you can select either spam space with a pre-set delay, or with a random delay (50-150 milliseconds), however, it keeps giving me errors and not working. Please help.

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.
#Persistent
Gui add, Button, PresetDelay, PresetDelay
Gui Add, Button, RandomDelay, RandomDelay
return


class PresetDelay {
#MaxThreadsPerHotkey 2
toggle = 0
v::
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        sleep 100                
    }
return
}

class RandomDelay {
#MaxThreadsPerHotkey 2
toggle = 0
v::
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        Random, rand, 50, 150
        sleep %rand%            
    }
return
}

User avatar
RaptorX
Posts: 395
Joined: 06 Dec 2014, 14:27
Contact:

Re: Help with Menu+Script

07 Apr 2018, 17:10

TeamIlluminati wrote:Hi, currently I'm trying to use the code below in order to have a menu in which you can select either spam space with a pre-set delay, or with a random delay (50-150 milliseconds), however, it keeps giving me errors and not working. Please help.
Spoiler
You have to use Gui Show somewhere in your program after you use Gui Add...

The menu is not showing because you havent told the program to do it. :)
Projects:
AHK-ToolKit
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 17:47

Oh, lol. The problem is that it gives me errors for every line in the functions. What am I doing wrong syntax wise? Thanks for the help btw.
User avatar
RaptorX
Posts: 395
Joined: 06 Dec 2014, 14:27
Contact:

Re: Help with Menu+Script

07 Apr 2018, 17:57

TeamIlluminati wrote:Oh, lol. The problem is that it gives me errors for every line in the functions. What am I doing wrong syntax wise? Thanks for the help btw.
You are for some reason using the Class syntax even though you are not creating classes at all. You are also referencing those "Classes" when adding the gui...

I think what you really want are Labels... not classes, in which case, the hotkeys might be redundant unless you want to trigger the action with the GUI and also with the hotkeys interchangeably.

Try this out and read the comments to understand some changes ;) :

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.
#Persistent
Gui add, button, gPresetDelay, PresetDelay
Gui add, button, gRandomDelay, RandomDelay
Gui show
return

PresetDelay:
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        sleep 100                
    }
toggle := 0 ; clean the toggle on exit for next round :)
return

RandomDelay:
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        Random, rand, 50, 150
        sleep %rand%            
    }
toggle := 0 ; clean the toggle on exit for next round :)
return

F12::toggle := !toggle ; actually you werent clearing the toggle in your code... you were bound to have an endless loop.
Projects:
AHK-ToolKit
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 18:36

It works now, thanks so much!
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 18:39

I want to add a function to reload (press key "r" when the ammunition in the corner is flashing red). So far, I have the code below, which is completely broken (presses random keys for some reason, glitches out and stuff).

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.
toggle = 0
#MaxThreadsPerHotkey 2

F9::
    Toggle := !Toggle
    While Toggle {
PixelGetColor, color, 1760, 991
if (color = FFFFFF) {
send r
Sleep, 1000         
}
}
return
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 18:43

Also, I want to be able to press v to activate it (the buttons being sort of a multiple choice thing, which ever one was clicked last, that is what "v" is hotkeyed to). How can I do that?
User avatar
RaptorX
Posts: 395
Joined: 06 Dec 2014, 14:27
Contact:

Re: Help with Menu+Script

07 Apr 2018, 18:52

TeamIlluminati wrote:Also, I want to be able to press v to activate it (the buttons being sort of a multiple choice thing, which ever one was clicked last, that is what "v" is hotkeyed to). How can I do that?
What is it that you want to activate with "v"? The reload script or the space script?

in either case you can just add "v::" to the beginning of the code you want to activate like so:

Code: Select all

RandomDelay:
v:: ; add the hotkey code to the part you want running
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        Random, rand, 50, 150
        sleep %rand%            
    }
toggle := 0 ; clean the toggle on exit for next round :)
return
Projects:
AHK-ToolKit
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Help with Menu+Script

07 Apr 2018, 19:03

I don't understand the thing you are saying about v, but one thing that seems wrong is the if-statement, try instead

Code: Select all

if (color = 0xFFFFFF)   {
because with your version you are comparing the contents of the variable color to the contents of a variable named FFFFFF - which doesn't exist, therefore empty. But you want to compare it to the hex number 0xFFFFFF instead (this is also the format that you get fromPixelGetcolor; add msgbox % color to confirm).
if (color = "0xFFFFFF") should also work.

Of course that wouldn't explain why your version would send keys at all ;)
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 19:10

Thanks so much guys. About the v; I want to have the v to activate a different script based on the button pressed (if that makes any sense). E.G. I press the random delay button and v now spams space with a random delay. If I press the pre-set delay, the v button will activate a script to spam space with a pre-set delay.
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

07 Apr 2018, 19:14

RaptorX wrote:
TeamIlluminati wrote:Also, I want to be able to press v to activate it (the buttons being sort of a multiple choice thing, which ever one was clicked last, that is what "v" is hotkeyed to). How can I do that?
What is it that you want to activate with "v"? The reload script or the space script?

in either case you can just add "v::" to the beginning of the code you want to activate like so:

Code: Select all

RandomDelay:
v:: ; add the hotkey code to the part you want running
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        Random, rand, 50, 150
        sleep %rand%            
    }
toggle := 0 ; clean the toggle on exit for next round :)
return
Unfortunately, this creates the error duplicate hotkey. I want to be able to change what the hotkey v does with the buttons.
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Help with Menu+Script  Topic is solved

07 Apr 2018, 19:55

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.
#maxthreadsperhotkey 2
Gui add, button, gPresetDelay, PresetDelay
Gui add, button, gRandomDelay, RandomDelay
Gui show
decision := 1
v::
	toggle := !toggle
		if decision = 1
			delay := 100
		if decision = 2
			random,delay,50,150
		 while toggle
			{
				send {space}
				sleep %delay%
			}	
return			
f9::
	toggle := !toggle
		if toggle
			settimer,reloadwep,1000
		else
			settimer,reloadwep,off
return

presetdelay:
	decision := 1
return

randomdelay:
	decision := 2
return

reloadwep:
		pixelgetcolor,pixel,1760, 991
		if color = 0xffffff;get your hex color and put it here 
		{
			send r
		}
return
	
User avatar
RaptorX
Posts: 395
Joined: 06 Dec 2014, 14:27
Contact:

Re: Help with Menu+Script

08 Apr 2018, 13:01

TeamIlluminati wrote:
RaptorX wrote:
TeamIlluminati wrote:Also, I want to be able to press v to activate it (the buttons being sort of a multiple choice thing, which ever one was clicked last, that is what "v" is hotkeyed to). How can I do that?
What is it that you want to activate with "v"? The reload script or the space script?

in either case you can just add "v::" to the beginning of the code you want to activate like so:

Code: Select all

RandomDelay:
v:: ; add the hotkey code to the part you want running
    Toggle := !Toggle
     While Toggle{
        Send {Space}
        Random, rand, 50, 150
        sleep %rand%            
    }
toggle := 0 ; clean the toggle on exit for next round :)
return
Unfortunately, this creates the error duplicate hotkey. I want to be able to change what the hotkey v does with the buttons.
You can't put the same hotkey twice.

Make "v" the hotkey for one of the labels and them make another letter the hotkey for the other label.
Projects:
AHK-ToolKit
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

10 Apr 2018, 08:32

Thank you guys so much for your help, especially donovv who found a clever workaround. Thank you RaptorX and gregster as well.
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

10 Apr 2018, 08:40

One last thing though, I want the reload script to be checking to reload every second or so, the script seems like it wants me to press f9 to reload, which isn't what I want. How do I do that (do I put it in a loop or something)?

EDIT: By "the script" I mean the script donovv made.

EDIT: Just found out that AHK uses BGR format for it's hex colors. Is that affecting my script in any way (I want it to detect the hex color for red)?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with Menu+Script

10 Apr 2018, 09:13

either call PixelGetColor with the RGB flag or do your comparisons in BGR

e: also you dont press f9 to reload, you press f9 to switch the timer checking for your reload cue on and off
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

10 Apr 2018, 10:59

So would the code below check for the color red? Or am I using it incorrectly?

Code: Select all

pixelgetcolor,pixel,1761, 985
		if color = 0x0000ff;get your hex color and put it here 
		{
			send r
		}
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

10 Apr 2018, 11:41

I realized a problem might be that text flashes red. So, instead of detecting red, I want it to press r at 1 second intervals if I am NOT holding down or clicking the left mouse button. How do I do that?

EDIT: I also want to be able to select different layouts for each of the characters. EX: for the sniper character, all it has to do it count how many times you shot, then reload once you shot 5 times (since I don't want to waste the ammo and you can't hold down). How do I could one down and up click with the left mouse button? I want the same for the shotgun, but I want it to edit it to make it every 2 clicks. I still want the thing I said above for the normal one. Sorry if I'm asking too much, if anyone could help point me in the right direction, that would be great :)
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Help with Menu+Script

10 Apr 2018, 15:05

I’ll give it a shot when I get off tonight but that’s about 4 hours from now
TeamIlluminati
Posts: 13
Joined: 07 Apr 2018, 15:51

Re: Help with Menu+Script

10 Apr 2018, 21:03

Thanks so much anyways :)!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 322 guests