Insert AHK Command/Function Parameters (with Search/Auto-Complete)

Discuss features, issues, about Editors for AHK
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Insert AHK Command/Function Parameters (with Search/Auto-Complete)

06 May 2017, 11:43

Intro:
This tool provides automatic insertion of the parameter definitions for AutoHotkey's commands, functions, and directives (will be referred to simply as commands for brevity).
  • It will auto-complete the command name using either of two incremental search modes: match from the beginning of the command name or match anywhere within it.
  • A list of available parameter definitions will be displayed. It will insert the parameter list for that command, allowing you to select among the alternatives if multiple are available.
  • It currently works with Notepad++, SciTE4AutoHotkey, AHK Studio, and AutoGUI. It should work with any editor that accepts pasted text and returns caret positions by adding the editor's WinTitle to the ahk_group.
I'd like to acknowledge Helgef's excellent AHK Hotstrings script which provides similar functionality. This tool is presented as an alternative or an addition to it. I can certainly see both being used as they each have their strengths, and either one can be invoked when desired. Many thanks to jeeswg and Helgef for their development of the command/parameters list, which I've made use of here.

I developed this tool so that it would include auto-complete in a parameter insertion tool (I'm too lazy to type long command names) and because the hotstrings-based tool works very slowly in the main place that I use it: in Notepad++ with auto-complete enabled. This is because a hotstring (and Send command) is basically typing out the text, so Notepad++'s auto-complete tries to suggest words for it as it types, causing it to operate very slowly. This tool pastes the text into your editor, making it immediate and eliminating this issue.

Usage:
  • Press CapsLock to invoke the command/function search, which will match from the start of the names:
    Image
  • Alternatively, press Shift + CapsLock so that command/function search will match anywhere:
    Image
    (You can of course change CapsLock and +CapsLock to any other hotkeys you wish.)
  • Use up/down arrow keys to navigate the matched entries or keep typing until the desired command is highlighted.
  • Press Enter to insert the command function name and to display its parameter definition(s).
  • If there is more than one parameter definition available, use the up/down arrow keys to select and press Enter to insert the parameters.
  • Press Escape at any time to exit without inserting the selection.
Download:
Insert AHK Parameters.ahk
(19.32 KiB) Downloaded 1668 times

Alternate version with ToolTips option
As suggested by BoBo, here is an alternate version that allows the parameters to be displayed as a ToolTip rather than insertion into the editor. Select option from tray icon. Initiate as usual and ToolTip will display instead. Press Esc or Exit to dismiss ToolTip.

Download alternate version:
Insert AHK Parameters_tooltip option.ahk
(20.35 KiB) Downloaded 592 times
Last edited by boiler on 09 Jul 2020, 22:40, edited 2 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

06 May 2017, 17:43

Very nice! :bravo:
The editbox solution is really smart I think, it solves all problems of tracking what is being typed.

I have worked on a similar script, but that project has spawned so many sidetracks that I'm not sure where it is going now :lol:

Anyways, great job and thanks for sharing.
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

07 May 2017, 10:44

Thanks! Glad you like it. I know the feeling about the sidetracks. :D

One of the throw-ins I added was the alternate incremental search mode where it matches anywhere, but I think maybe it should be the primary mode under the main hotkey. Sometimes I remember part of a command's name but not how it starts, like the various trim commands/functions (AutoTrim, LTrim, RTrim StringTrimLeft, etc.).
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

07 May 2017, 11:29

Yes match anywhere is very nice.
It is very easy to modify and add to this script. Five minute effort, here is all gdip_ functions (currently in my user lib)

Code: Select all

p2=
(
Gdip_BitmapFromBRA;(ByRef BRAFromMemIn, File, Alternate=0) 
Gdip_DrawRectangle;(pGraphics, pPen, x, y, w, h) 
Gdip_DrawRoundedRectangle;(pGraphics, pPen, x, y, w, h, r) 
Gdip_DrawEllipse;(pGraphics, pPen, x, y, w, h) 
Gdip_DrawBezier;(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4) 
Gdip_DrawArc;(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 
Gdip_DrawPie;(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) 
Gdip_DrawLine;(pGraphics, pPen, x1, y1, x2, y2) 
Gdip_DrawLines;(pGraphics, pPen, Points) 
Gdip_FillRectangle;(pGraphics, pBrush, x, y, w, h) 
Gdip_FillRoundedRectangle;(pGraphics, pBrush, x, y, w, h, r) 
Gdip_FillPolygon;(pGraphics, pBrush, Points, FillMode=0) 
Gdip_FillPie;(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle) 
Gdip_FillEllipse;(pGraphics, pBrush, x, y, w, h) 
Gdip_FillRegion;(pGraphics, pBrush, Region) 
Gdip_FillPath;(pGraphics, pBrush, Path) 
Gdip_DrawImagePointsRect;(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1) 
Gdip_DrawImage;(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1) 
Gdip_SetImageAttributesColorMatrix;(Matrix) 
Gdip_GraphicsFromImage;(pBitmap) 
Gdip_GraphicsFromHDC;(hdc) 
Gdip_GetDC;(pGraphics) 
Gdip_ReleaseDC;(pGraphics, hdc) 
Gdip_GraphicsClear;(pGraphics, ARGB=0x00ffffff) 
Gdip_BlurBitmap;(pBitmap, Blur) 
Gdip_SaveBitmapToFile;(pBitmap, sOutput, Quality=75) 
Gdip_GetPixel;(pBitmap, x, y) 
Gdip_SetPixel;(pBitmap, x, y, ARGB) 
Gdip_GetImageWidth;(pBitmap) 
Gdip_GetImageHeight;(pBitmap) 
Gdip_GetImageDimensions;(pBitmap, ByRef Width, ByRef Height) 
Gdip_GetDimensions;(pBitmap, ByRef Width, ByRef Height) 
Gdip_GetImagePixelFormat;(pBitmap) 
Gdip_GetDpiX;(pGraphics) 
Gdip_GetDpiY;(pGraphics) 
Gdip_GetImageHorizontalResolution;(pBitmap) 
Gdip_GetImageVerticalResolution;(pBitmap) 
Gdip_BitmapSetResolution;(pBitmap, dpix, dpiy) 
Gdip_CreateBitmapFromFile;(sFile, IconNumber=1, IconSize="") 
Gdip_CreateBitmapFromHBITMAP;(hBitmap, Palette=0) 
Gdip_CreateHBITMAPFromBitmap;(pBitmap, Background=0xffffffff) 
Gdip_CreateBitmapFromHICON;(hIcon) 
Gdip_CreateHICONFromBitmap;(pBitmap) 
Gdip_CreateBitmap;(Width, Height, Format=0x26200A) 
Gdip_SetBitmapToClipboard;(pBitmap) 
Gdip_CloneBitmapArea;(pBitmap, x, y, w, h, Format=0x26200A) 
Gdip_CreatePen;(ARGB, w) 
Gdip_CreatePenFromBrush;(pBrush, w) 
Gdip_BrushCreateSolid;(ARGB=0xff000000) 
Gdip_BrushCreateHatch;(ARGBfront, ARGBback, HatchStyle=0) 
Gdip_CreateTextureBrush;(pBitmap, WrapMode=1, x=0, y=0, w="", h="") 
Gdip_CreateLineBrush;(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1) 
Gdip_CreateLineBrushFromRect;(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1) 
Gdip_CloneBrush;(pBrush) 
Gdip_DeletePen;(pPen) 
Gdip_DeleteBrush;(pBrush) 
Gdip_DisposeImage;(pBitmap) 
Gdip_DeleteGraphics;(pGraphics) 
Gdip_DisposeImageAttributes;(ImageAttr) 
Gdip_DeleteFont;(hFont) 
Gdip_DeleteStringFormat;(hFormat) 
Gdip_DeleteFontFamily;(hFamily) 
Gdip_DeleteMatrix;(Matrix) 
Gdip_TextToGraphics;(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0) 
Gdip_DrawString;(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF) 
Gdip_MeasureString;(pGraphics, sString, hFont, hFormat, ByRef RectF) 
Gdip_SetStringFormatAlign;(hFormat, Align) 
Gdip_StringFormatCreate;(Format=0, Lang=0) 
Gdip_FontCreate;(hFamily, Size, Style=0) 
Gdip_FontFamilyCreate;(Font) 
Gdip_CreateAffineMatrix;(m11, m12, m21, m22, x, y) 
Gdip_CreatePath;(BrushMode=0) 
Gdip_AddPathEllipse;(Path, x, y, w, h) 
Gdip_AddPathPolygon;(Path, Points) 
Gdip_DeletePath;(Path) 
Gdip_SetTextRenderingHint;(pGraphics, RenderingHint) 
Gdip_SetInterpolationMode;(pGraphics, InterpolationMode) 
Gdip_SetSmoothingMode;(pGraphics, SmoothingMode) 
Gdip_SetCompositingMode;(pGraphics, CompositingMode=0) 
Gdip_Shutdown;(pToken) 
Gdip_RotateWorldTransform;(pGraphics, Angle, MatrixOrder=0) 
Gdip_ScaleWorldTransform;(pGraphics, x, y, MatrixOrder=0) 
Gdip_TranslateWorldTransform;(pGraphics, x, y, MatrixOrder=0) 
Gdip_ResetWorldTransform;(pGraphics) 
Gdip_GetRotatedTranslation;(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation) 
Gdip_GetRotatedDimensions;(Width, Height, Angle, ByRef RWidth, ByRef RHeight) 
Gdip_ImageRotateFlip;(pBitmap, RotateFlipType=1) 
Gdip_SetClipRect;(pGraphics, x, y, w, h, CombineMode=0) 
Gdip_SetClipPath;(pGraphics, Path, CombineMode=0) 
Gdip_ResetClip;(pGraphics) 
Gdip_GetClipRegion;(pGraphics) 
Gdip_SetClipRegion;(pGraphics, Region, CombineMode=0) 
Gdip_DeleteRegion;(Region) 
Gdip_LockBits;(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a) 
Gdip_UnlockBits;(pBitmap, ByRef BitmapData) 
Gdip_SetLockBitPixel;(ARGB, Scan0, x, y, Stride) 
Gdip_GetLockBitPixel;(Scan0, x, y, Stride) 
Gdip_PixelateBitmap;(pBitmap, ByRef pBitmapOut, BlockSize) 
Gdip_ToARGB;(A, R, G, B) 
Gdip_FromARGB;(ARGB, ByRef A, ByRef R, ByRef G, ByRef B) 
Gdip_AFromARGB;(ARGB) 
Gdip_RFromARGB;(ARGB) 
Gdip_GFromARGB;(ARGB) 
Gdip_BFromARGB;(ARGB) 
)
CommandText.= "`n" p2

Sort,CommandText ; I don't know if this is needed, I just guessed.
Paste here:

Code: Select all

CommandListing:
CommandText = 
(
...
)
;PASTE here:
p2=
(
...
)
return
The list was generated with this script Insert User Function Definitions -- for Notepad++, specifically see my post :D

Any thought on using the function script for auto-adding functions in current script or something like that? :geek:

Cheers.
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

08 May 2017, 20:46

That's a nice addition and a good point in general that anyone can add any library functions to this that they want using your technique. :thumbup:
A couple notes to others looking to do the same:
  • It is important to put the text for your additions in its own continuation section as Helgef did, which is to define a variable whose contents are between its own pair parentheses, then concatenate it to the CommandText variable. This is because there is a limit to how many characters a single continuation section can contain, and the main command/function/directive list is pushing that limit. Per the AHK documentation: "A continuation section cannot produce a line whose total length is greater than 16,383 characters."
  • If the text of what you add includes a ";" character, it will cause a minor problem because I chose that character as a delimiter in the list between the name of the command and its parameters.
Helgef wrote:Any thought on using the function script for auto-adding functions in current script or something like that?
This is a good idea, and I have been thinking it would be nice to combine the two, but I haven't yet put any effort into it yet. The one issue I thought about is that it would only work with editors that show the full path in the window title as Notepad++ so it can find the #Include files, but that's okay. It would be a nice project for a rainy day...
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 01:59

I think Scite4AutoHotkey and AHKStudio both offer a COMObject to get that sort of data.
Recommends AHK Studio
Guest

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 03:01

Useful - Some thoughts:

* CommandText should be separated from the script in its own file(folder?). That way you can modify the script more easily and exchange update without the need to mess with it.

* You can have multiple CommandTexts files, makes it easy to update the externally and reload the script (external script can reload your script to update it)

* Look at Goto/TillaGoto for some code to "find" functions in the current edited file so they can be added dynamically or on "user activated scan" https://github.com/ahkscript/awesome-AutoHotkey/#others (could include a "scan project" so it scans all #includes)

* Also here https://github.com/ahkscript/awesome-AutoHotkey/#others is "quick help in any editor" which could be integrated.

:)
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 19:31

@nnik: That should come in handy. Thanks for the info.

@Guest:
I considered whether to put the CommandText data in the script file, and I ended up thinking that a single file might make it more convenient for people. I typically lean towards what you recommended. And your suggestion about them possibly being in a separate folder might be better because then it could read any and all files in that folder, making it easier to manage adding library function definitions as Helgef did. Sounds like a worthwhile change in a future update.

I did briefly look at GotoTilla and TillaGoto but didn't end up reverse engineering their code for that part (although I did look at what they did for their combined edit box/list box). I may revisit them if I do tackle the task of integrating user functions into this, although I may just use what I already do in my other script for that at first since I primarily use Notepad++ at the moment.

Thanks for the link to the context-sensitive help. I have been using Rajat's version of that. I can see how something like that might be worthwhile to tie into this, although I find it works fine as a separate script. I suppose the main reason to do it is to reduce the number of scripts you have running.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

02 Jan 2020, 16:18

Hi,

I took the liberty to convert your script into a class and extended the AHK Items to directives, keywords, keys, methods and properties and flow commands.
It works similar to your original script. There are a few differences.
Capslock always shows the edit control. with Shift+Capslock the algorithm can be changed while typing.

It works in general. But I have a problem with the escape sequences.
For some predefined function bodies, e.g. gGuiControlLabel(CtrlHwnd, GuiEvent, EventInfo, ErrLevel:="")`n{`n`t|`b|`r}
, and flow of control commands, e.g. Loop [, Count]`n{`n |`n}, I have set `n and `t.
For some reason they do not expand to Enter and Tab when send to Notepad++ or Notepad.
It works when I use the Send command on a hotkey or in a function. But it doesn't work with this class. Don't know why. Any hint appreciated.
Attachments
InsertAHKItems.7z
(10.44 KiB) Downloaded 418 times
ciao
toralf
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

02 Jan 2020, 23:09

It looks like a very nice update and extension. Thanks for sharing it.

It may not be expanding the `n and `t because of the way the original uses a paste (sending text using Control+v) rather than using Send. See the function named Paste(). (I did this to avoid the issues with Notepad++'s built-in autocomplete trying to expand the text as it is sent if done using the Send command.) I tried seeing if there was an easy fix to the `n and `t issue by changing the send method in the Paste() function to Send (or alternatively SendInput) instead of Control+v, but then the editor was losing focus and causing issues for some reason. It doesn't do that when I change my original version to use Send instead of Control+v, so it seems to be related to how the class is using it, but I can't see why at this point. I imagine it can be resolved, though.
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

03 Jan 2020, 02:52

I will have to resolve the escape sequences in the code. They are not resolved because they are read from file. In your original Script thy were script literal and than they are resolved automatically....
Or I’ll include the files.
ciao
toralf
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 Jul 2020, 22:30

Added alternate version to initial post that allows for an option to show parameters as ToolTips instead.
KaitB
Posts: 1
Joined: 25 Apr 2021, 18:42

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

25 Apr 2021, 19:09

Hey, thanks for the script!
I know this is a relatively old post, but I found a strange bug in your script.
When I first tried it, it simply did not work. When you hit "return" after selecting the function, nothing would appear. After some testing and messing arround with the script, I noticed that my clipboard was being pasted instead of the SelectedCommand.
Since I am a newb at AHK coding, I don't know what is actually happening, but I figured that including a sleep with 150ms before "send, ^v" fixed the problem for me.

Also, is there a way to make this script run automatically every time np++ is lauched?

Code: Select all

Paste(text)
{
	IfWinActive, ahk_exe ahk_exe SciTE.exe
		ControlFocus, Scintilla1, A ; so that find/replace pane doesn't get focus
	savedClip := ClipboardAll
	Clipboard := text
	;MsgBox, Message: %text%
	Sleep, 150
	Send, ^v
	Clipboard := savedClip
}
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

25 Apr 2021, 20:04

KaitB wrote:
25 Apr 2021, 19:09
is there a way to make this script run automatically every time np++ is lauched?
I don’t know a way to have it do that without having another script always running that would monitor when it’s open or not. A better way, in my opinion, would be to modify this script to run NP++ when a you run it, and it closes itself when NP++ closes. Then you’re still running and closing only one thing. You could even give it a NP++ icon and similar name (Notepad+++ ?) so that it looks visually like you’re opening NP++.
Technomage Awunes
Posts: 9
Joined: 25 Oct 2021, 20:33

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

27 May 2023, 10:18

It's funny you suggest this:
You could even give it a NP++ icon and similar name (Notepad+++ ?) so that it looks visually like you’re opening NP++.
I made a script after seeing my son's discord post of an Alien virus that says it's technology isn't able to do anything but if you'd be so kind as to delete one of your important files and pass it on to your friends it'd know it could trust you and would let you load the program you requested. I made it look like the autoclicker and would open the auto clicker which was in a file include ... Anyway just funny that you suggested that :)

It was a joke for him (not a real virus) but microsoft decided it had to scan it as it'd never seen the exe before and it had characteristics of a virus ... It was quite interesting... Wish I could find the original script to share with y'all
User avatar
boiler
Posts: 16766
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

27 May 2023, 10:48

Technomage Awunes wrote: It was a joke for him (not a real virus) but microsoft decided it had to scan it as it'd never seen the exe before and it had characteristics of a virus ... It was quite interesting... Wish I could find the original script to share with y'all
Not to be a “Debbie Downer,” but it’s just as well that you didn’t share it because posting prank scripts is against the Forum Rules. Pranks that emulate a virus especially give AHK a bad reputation.

Return to “Editors”

Who is online

Users browsing this forum: No registered users and 8 guests