Help on where and how to start scripting.(and a plus)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
youdontknowme
Posts: 14
Joined: 03 Aug 2017, 10:40

Help on where and how to start scripting.(and a plus)

03 Aug 2017, 10:51

Hello everyone, first post here..

To start, i only programmed basic scripts (like this one)
Spoiler
But i had read a lot of advanced scripts like with functions or so... I just turn interested on write ones like those.

First... Where do you code it? it isn't on notepad like mine, right?
Then... I need to know if theres is a chance to create a script that is passive/hided... One that know what you do on a Google Chrome Tab and plus or minus on his GUI...

Like... if i press on X, then, it plus a number in the gui's script.. but if instead i press on Y, it minus the number in gui.

PD: If what im writing isn't clear, ill post images...
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Help on where and how to start scripting.(and a plus)

03 Aug 2017, 11:33

Hello there!

You can find a lot of information through the AutoHotKey documentation
Also another great resource is youtube

As far as the editor goes, I personally use Notepad++ with AutoHotKey syntax highlighting, there is also an ahk specific editor here https://autohotkey.com/boards/viewtopic.php?f=61&t=62

I've also written a simple script with comments that you may find useful

Code: Select all

counter := 0 ;initiate variable
gui,add,text,x5 y5 w200 h20 vcounterText,Count: 0 ;add text to the gui, vcounterText sets counterText as a variable associated with this control
gui,add,button,x5 y25 w150 h20 greset,Reset Counter ;add a button, when clicked goes to label "reset"
gui,show,x50 y50,Gui   ;not specifying width/height causes it to autosize
return ;tells the script to return

msgbox hello ;because of the return above, this code never gets executed

x:: ;hotkeys use 2 colons
counter++ ;simplest way to increase a variable by 1
guicontrol,,counterText, % "Count: " counter  ;update the text control
;guicontrol,,counterText, Count: %counter%  ;this also works
return

y::
counter-- ;simplest way to reduce a variable by 1 
;counter -= 1 ;other was of doing it
;counter := counter - 1
guicontrol,,counterText, % "Count: " counter
return

reset: ;labels only use 1 colon
while(counter != 0) { ;while counter does not equal 0
	counter := ResetCounter(counter) ;counter becomes the return value of ResetCounter function
	guicontrol,,counterText, % "Count: " counter ;update text
	sleep 500 ;sleep 500ms,  1000ms == 1 second
}
msgbox Finished resetting counter!
return

guiclose: ;built in event that fires when a gui is closed
exitapp ;when gui is closed, exit the program

ResetCounter(value) { ;FunctionName(parameters)
	if (value > 0) {
		value-- ;if value larger than 0, minus by 1
	} else if (value < 0) {
		value++ ;if lower than 0, increase by 1
	}
	return value ;return the new value
}
I started learning AHK first by watching video guides, then dissecting working scripts and browsing the documentation.

Good luck! :thumbup:
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Help on where and how to start scripting.(and a plus)

03 Aug 2017, 11:43

I used NotePad++ for quite a while, but now I highly recommend SciTE4AutoHotkey, which you can find here: https://fincs.ahk4.net/scite4ahk/

Compared to NotePad++ it has somewhat more intelligent highlighting, and some other cool features like you can right click on an #Include line to open the included file.

EDIT: Didn't see that you already included a link to Scite, Spawnova, sorry. ^^;
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Help on where and how to start scripting.(and a plus)

03 Aug 2017, 18:22

I've not used NotePad++, but I love AHK Studio!
youdontknowme
Posts: 14
Joined: 03 Aug 2017, 10:40

Re: Help on where and how to start scripting.(and a plus)

04 Aug 2017, 12:50

Well, thank you all by answers!
I have writed this

Code: Select all

#Singleinstance Force

counter := 0 ;initiate variable
Counter2 := 0
counter3 := 0
counter4 := 0

gui,font, s11, Verdana, w450

gui,add,text,x5 y5 w150 h20 vcounterText,Bandejas: 0
gui,add,text,x5 y25 w150 h20 vcounter2Text,Cerradas: 0
gui,add,text,x5 y45 w150 h20 vcounter3Text,Pendientes: 0
gui,add,text,x5 y65 w150 h20 vcounter4Text,Derivadas: 0 ;add text to the gui, vcounterText sets counterText as a variable associated with this control

Gui +LastFound +AlwaysOnTop +ToolWindow -Theme -Border
Gui, Margin, 5, 5

OnMessage(0x201, "WM_LBUTTONDOWN")

gui,show,x50 y50,Contador   ;not specifying width/height causes it to autosize
return

WM_LBUTTONDOWN() {

	PostMessage, 0xA1, 2

}

!Numpad7:: ;Sumar una cerrada / mas una bandeja

	counter2++
	counter++ ;simplest way to increase a variable by 1

	guicontrol,,counterText, % "Bandejas: " counter  ;update the text control
	guicontrol,,counter2Text, % "Cerradas: " counter2

return

!Numpad8:: ;Sumar una Pendiente / mas una bandeja

	counter3++
	counter++ ;simplest way to increase a variable by 1

	guicontrol,,counterText, % "Bandejas: " counter  ;update the text control
	guicontrol,,counter3Text, % "Pendientes: " counter3

return

!Numpad9:: ;Sumar una Derivada / mas una bandeja

	counter4++
	counter++ ;simplest way to increase a variable by 1

	guicontrol,,counterText, % "Bandejas: " counter  ;update the text control
	guicontrol,,counter4Text, % "Derivadas: " counter4

return

!Numpad1:: ;Restar una Cerrada / una bandeja menos
	counter2--
	counter-- ;simplest way to reduce a variable by 1 

	guicontrol,,counterText, % "Bandejas: " counter
	guicontrol,,counter2Text, % "Cerradas: " counter2

return

!Numpad2:: ;Restar una Pendiente / una bandeja menos
	counter3--
	counter-- ;simplest way to reduce a variable by 1 

	guicontrol,,counterText, % "Bandejas: " counter
	guicontrol,,counter3Text, % "Pendientes: " counter3

return

!Numpad3:: ;Restar una Derivada / una bandeja menos
	counter4--
	counter-- ;simplest way to reduce a variable by 1 

	guicontrol,,counterText, % "Bandejas: " counter
	guicontrol,,counter4Text, % "Derivadas: " counter4

return

guiclose: ;built in event that fires when a gui is closed
exitapp ;when gui is closed, exit the program
As you can see i changed a lot of things, but the essence of this is what you post to me @Spawnova.

Now.. i have new questions... Is a chance to make the script KNOW what i'm doing on chrome and if i make X action, the counter increments by itself?

Anyone know how to make the background of the GUI translucent?
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Help on where and how to start scripting.(and a plus)

04 Aug 2017, 20:13

Check WinSet, Transparent/Transcolor
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Help on where and how to start scripting.(and a plus)

04 Aug 2017, 21:33

youdontknowme wrote:First... Where do you code it? it isn't on notepad like mine, right?
To clarify, scripts are plain-text, UTF-8/16 (WITH BOM) encoded for the Unicode version, or ANSI for the ANSI version. Therefore, any editor that can encode to the respective format will work: notepad, Notepad++, SublimeText, AHK Studio, SciTE4AHK, or even Visual Studios, Eclipse, Microsoft Edit (deprecated), VIM.. Whatever interface you prefer, really.
youdontknowme wrote:One that know what you do on a Google Chrome Tab
Browser interfaces are notoriously difficult to interact with due to the way they render (IE exempt, because you have COM for that). I believe there are several functions for grabbing info from Chrome, a Google search will do it for you.

I assume by "passive" you mean "mostly idle." You can use SetTimer to do checks for things at specified intervals.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Google [Bot], Shikoweno and 158 guests