Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Dynamically create and execute labels -- NO reload


  • Please log in to reply
5 replies to this topic
Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

First and foremost, this method requires Autohotkey_H. Second, the most important thing to be sure of is to use the right dll. If you are using AHK 32 Unicode, then use that version of the dll; the dll type should match the executable.

 

Although when you look at Autohotkey_H this seems like something you can obviously do, I haven't seen any specific examples on how to accomplish this; on the contrary, I have only seen posts claiming that this is impossible or extremely difficult to script.

 

So here's a very basic example of how to accomplish this.

Spoiler

 

Currently, the way I like to implement this is to create a function that dynamically creates the code for the label, loads that up into a variable, and then passed that variable into ahktextdll.

 

I like using the hotkey label simply as a wrapper back to a function (or label) in Autohotkey.exe so that I can keep the brunt of my code in my main script. This is a cleaner approach, IMHO, and it leaves less room for error.

 

Note: the dll thread is not multi-thread safe. For those of you who need to ensure multi-threading safety, use the CriticalObject function


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
cool, thanks for sharing

Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Sure thing!


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Updated example with a GUI that clearly demonstrates this.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

You forgot to include LV_GetSel().

You also don't need to call AhkDllThread over and over again, run the second line only once at the top of the script!

        g_hThread :=
        g_hThread := AhkDllThread()

you can also show the script in second column so user knows what the code was and why did you limit edit to one line?

...
Gui, Add, Edit, x2 y110 w350 h70 Multi r3 vsAHKScript
...
Gui, Add, ListView, x2 y190 w350 h150 AltSubmit gLVProc, Hotkey|Script
...
LV_Add("", sHK,sAHKScript)
...


Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Thanks, HotKeyIt! I made all of those changes.

 

The Edit was limited to one row because I thought it was causing errors in the continuation section where I build the labels.


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.