Page 1 of 1

Simple Commenting Tool

Posted: 14 Feb 2019, 03:13
by electrified
Hey guys,
This is obviously a lot of code for nothing but I always wanted to be able to automatically place a separator comment and the word to be centered without any manual intervention. I tried searching for such a tool countless times but to no avail so i decided to give it a try and see if i will be able to pull this off on my own.
Let me show you what i mean.

;#########################################~Hotkeys~##########################################
;########################################~Hotstrings~#########################################

As I am still a noob there is probably a much better way to achieve this than the way i have done it but for me the important thing is that it does what it has been designed for. I will be happy if someone finds it usefull. If not, i'll still use it for my scripts :D

I have tested it in notepad and in SciTE and so far it works flawlessly. It is limited to 32 characters but still those are a lot of letters you can use for a comment

Code: Select all

#SingleInstance, Force

Gui, +AlwaysOnTop
Gui, Font, s10 Verdana
Gui, Add, Edit, vCommentWord h20 w220 Limit32,		; Limit the field entry to 32 symbols
Gui, Add, Button, x95 y35 h22 w60 gOk, OK
Gui, Show, AutoSize
Return

Ok:
Gui, Submit, NoHide
MsgBox, 262180,, Do you wish to use the following as your comment?`n%CommentWord%
	IfMsgBox, Yes
	{
			NumVar := % StrLen(CommentWord)			; Calculating what is the lenght of the word/s you have entered and saving it in a variable
			NumVarHalf := NumVar/2					; Dividing the number and saving it in another variable
		GuiControl,, CommentWord					; Clearing the GUI edit box
	MsgBox, 262144,, Use F12 to paste the comment!
	}
	else
		GuiControl,, CommentWord
Return

F12::
If (NumVarHalf = 0.5){												; If the devided number equals 0.5 (i.e. you have entered only 1 symbol) execute the following:
		FinalNum := NumVarHalf*90									; Multiplying the devided number by 90 (just a random number of preference (45 in this case) for the symbols on both sides of the word/s you chose)
		FinalNum2 := FinalNum-1										; As the result is an odd number we remove 1 
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}		; The displayed result is 44 "#" symbols ~ the word/s you chose ~ 45 "#" symbols (Again, as it is an odd number by removing the first symbol, visually it should appear as if in the middle)
}
	If (NumVarHalf = 1){
		FinalNum := NumVarHalf*44
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 1.5){
		FinalNum := NumVarHalf*29.5
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 2){
		FinalNum := NumVarHalf*21.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 2.5){
		FinalNum := NumVarHalf*17.5
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 3){
		FinalNum := NumVarHalf*14.3
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 3.5){
		FinalNum := NumVarHalf*12.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 4){
		FinalNum := NumVarHalf*10.4
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 4.5){
		FinalNum := NumVarHalf*9.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 5){
		FinalNum := NumVarHalf*8
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 5.5){
		FinalNum := NumVarHalf*7.3
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 6){
		FinalNum := NumVarHalf*6.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 6.5){
		FinalNum := NumVarHalf*6
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 7){
		FinalNum := NumVarHalf*5.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 7.5){
		FinalNum := NumVarHalf*5.1
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 8){
		FinalNum := NumVarHalf*4.7
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 8.5){
		FinalNum := NumVarHalf*4.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 9){
		FinalNum := NumVarHalf*4
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 9.5){
		FinalNum := NumVarHalf*3.8
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 10){
		FinalNum := NumVarHalf*3.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 10.5){
		FinalNum := NumVarHalf*3.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 11){
		FinalNum := NumVarHalf*3.1
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 11.5){
		FinalNum := NumVarHalf*3
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 12){
		FinalNum := NumVarHalf*2.8
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 12.5){
		FinalNum := NumVarHalf*2.7
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 13){
		FinalNum := NumVarHalf*2.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 13.5){
		FinalNum := NumVarHalf*2.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 14){
		FinalNum := NumVarHalf*2.25
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 14.5){
		FinalNum := NumVarHalf*2.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 15){
		FinalNum := NumVarHalf*2
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 15.5){
		FinalNum := NumVarHalf*1.95
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 16){
		FinalNum := NumVarHalf*1.87
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
Return

GuiClose:
ExitApp

Re: Simple Commenting Tool

Posted: 14 Feb 2019, 11:23
by AHKStudent
Useful, inspired by your work I put together something that maybe you can make work, even this version can be shorter and be easier,

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
gui, +AlwaysOnTop
Gui Add, Edit, hWndhEdit3 x9 y62 w184 h21 vthecomment
DllCall("SendMessage", "Ptr", hEdit3, "UInt", 0x1501, "Ptr", 1, "WStr", "Title") 
Gui Add, Text, x9 y6 w67 h25 +0x200, The Symbol?
Gui Add, Edit, x78 y9 w23 h21 Center Limit1 vTheChar, #
Gui Add, Text, x9 y36 w64 h23 +0x200, Length
Gui Add, Edit, x78 y37 w24 h21 +Number vMaxChars, 40
Gui Add, Button, x114 y88 w80 h23 gGenerate, Generate
gui, font, cRed bold
Gui Add, Text, x11 y115 w182 h25 +0x200 center valerts,
gui, font
Gui Show, w205 h143, CreateTitles
hotkey, Q, Off
Return

Generate:
Gui, Submit, NoHide
maxcharmin := (maxchars - 2)
if (StrLen(thecomment) >= maxcharmin)
{
   guicontrol,, alerts, Too much text
   Sleep, 1650
   guicontrol,, alerts,
   return
}
hotkey, Q, On
guicontrol,, alerts, Position your cursor and press Q
return

q::
comstr =
Gui, Submit, NoHide
startchar := (maxchars - StrLen(thecomment)) // 2
loop, % startchar
   comstr .= thechar
loop, 1
   comstr .= " " thecomment " "
loop, % startchar
   comstr .= thechar
SendInput {Raw}; %comstr%
hotkey, Q, Off
guicontrol,, alerts,
GuiControl, Focus, Edit1
ControlSend, Edit1, ^a, CreateTitles
return

GuiEscape:
GuiClose:
    ExitApp

Re: Simple Commenting Tool

Posted: 15 Feb 2019, 05:17
by electrified
Thanks :)
I really didn't think there will be any interest on this.

Thank you for posting a different approach AHKStudent :)

Re: Simple Commenting Tool

Posted: 15 Feb 2019, 14:57
by ahk7
It you want something bigger: Big notes for big programs

Re: Simple Commenting Tool

Posted: 15 Feb 2019, 22:52
by godofOOF
Nice script :dance: but i decided to make it a little more user friendly and

more attractive with a bit of modifying the only thing i really improved on is the look of the gui

but the core functionality is still there :clap:





Download Here:
Simple Commenting Tool.ahk
(6.96 KiB) Downloaded 138 times


Source:

Code: Select all

;You Can also open up the discusstion by clicking on the "simplecommenter" Text
;TOPIC: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62026
; CREATED AND MADE BY electrified  (Account: https://tinyurl.com/yxt88esa)
 ; Partly Modified by godofOOF 
 
;###########################################################################################################################################################




;###############################~Helps make the script Faster~###############################
; got this from forumhttps://www.autohotkey.com/boards/viewtopic.php?f=7&t=6413
;Menu, Tray, Noicon,
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
;the Unicode x64bit version is the fastest AHK installation
;use PixelSearch without Fast if you're searching for a single pixel of a single shade
DllCall("Sleep",UInt,16.67) ;I just used the precise sleep function to wait exactly 16,67 milliseconds!

#SingleInstance, Force
;###############################~Helps make the script Faster~###############################



Gui, Font, s12, Segoe UI 
Gui, Add, Text, cWhite Ggui_main_title, SimpleComment
Gui, Color, 383839, 
Gui, Margin, 15, 15
Gui, +AlwaysOnTop -caption -ToolWindow -caption +Border
Gui, Font, s10 Verdana
Gui, Add, Edit, vCommentWord h20 w205 Limit36,		; Limit the field entry to 36 symbols
Gui, Add, Button, x85 y70 h30 w60 gOk, OK
Gui, Add, Button, x35 y70 h22 w47.6 gGuiClose, Exit
Gui, Add, Button, x150 y70 h22 w50 gCreator, Close
SoundBeep
Gui, Show, AutoSize
Return


Ok:
Gui, Submit, NoHide
MsgBox, 262180,, Do you wish to use the following as your comment?`n%CommentWord%
	IfMsgBox, Yes
	{
			NumVar := % StrLen(CommentWord)			; Calculating what is the lenght of the word/s you have entered and saving it in a variable
			NumVarHalf := NumVar/2					; Dividing the number and saving it in another variable
		GuiControl,, CommentWord					; Clearing the GUI edit box
	MsgBox, 262144,, Use F12 to paste the comment!
	}
	else
		GuiControl,, CommentWord
Return

F12::
If (NumVarHalf = 0.5){												; If the devided number equals 0.5 (i.e. you have entered only 1 symbol) execute the following:
		FinalNum := NumVarHalf*90									; Multiplying the devided number by 90 (just a random number of preference (45 in this case) for the symbols on both sides of the word/s you chose)
		FinalNum2 := FinalNum-1										; As the result is an odd number we remove 1 
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}		; The displayed result is 44 "#" symbols ~ the word/s you chose ~ 45 "#" symbols (Again, as it is an odd number by removing the first symbol, visually it should appear as if in the middle)
}
	If (NumVarHalf = 1){
		FinalNum := NumVarHalf*44
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 1.5){
		FinalNum := NumVarHalf*29.5
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 2){
		FinalNum := NumVarHalf*21.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 2.5){
		FinalNum := NumVarHalf*17.5
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 3){
		FinalNum := NumVarHalf*14.3
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 3.5){
		FinalNum := NumVarHalf*12.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 4){
		FinalNum := NumVarHalf*10.4
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 4.5){
		FinalNum := NumVarHalf*9.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 5){
		FinalNum := NumVarHalf*8
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 5.5){
		FinalNum := NumVarHalf*7.3
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 6){
		FinalNum := NumVarHalf*6.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 6.5){
		FinalNum := NumVarHalf*6
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 7){
		FinalNum := NumVarHalf*5.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 7.5){
		FinalNum := NumVarHalf*5.1
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 8){
		FinalNum := NumVarHalf*4.7
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 8.5){
		FinalNum := NumVarHalf*4.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 9){
		FinalNum := NumVarHalf*4
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 9.5){
		FinalNum := NumVarHalf*3.8
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 10){
		FinalNum := NumVarHalf*3.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 10.5){
		FinalNum := NumVarHalf*3.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 11){
		FinalNum := NumVarHalf*3.1
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 11.5){
		FinalNum := NumVarHalf*3
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 12){
		FinalNum := NumVarHalf*2.8
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 12.5){
		FinalNum := NumVarHalf*2.7
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 13){
		FinalNum := NumVarHalf*2.5
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 13.5){
		FinalNum := NumVarHalf*2.4
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 14){
		FinalNum := NumVarHalf*2.25
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 14.5){
		FinalNum := NumVarHalf*2.2
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 15){
		FinalNum := NumVarHalf*2
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 15.5){
		FinalNum := NumVarHalf*1.95
		FinalNum2 := FinalNum-1
	SendInput, `;{# %FinalNum2%}~%CommentWord%~{# %FinalNum%}
}
	If (NumVarHalf = 16){
		FinalNum := NumVarHalf*1.87
	SendInput, `;{# %FinalNum%}~%CommentWord%~{# %FinalNum%}
}
Return

Creator:
WinMinimize, Simple Commenting Tool.ahk
return

GuiClose:
SoundBeep
ExitApp

gui_main_title:
Run, https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62026
return
Thanks for the script its really useful :D

Re: Simple Commenting Tool

Posted: 23 Feb 2019, 00:52
by DataLife
Thanks for this script. I put comments like that in my scripts all the time. I am constantly trying to center my comments.

I removed the "Do you wish to use the following as your comment?" and the "Use F12 to paste the comment!" message boxes to make it quicker to add comments.

Re: Simple Commenting Tool

Posted: 25 Feb 2019, 03:39
by ozzii
For a faster commenting, you can:
-Write the texte
-F12 wich
1-select the line
2-copy the selected text
4-launch the commenting function
5-past the commented texte