Jump to content
Sign in to follow this  

writing func's from within a func?

Recommended Posts


I was bored today so I've been trying to make a function that could write another function based on input.

Here is what I want to do:

Func pressed()
    $i += 1
    Until $g==$i
    Switch $i
        Case 1
        Case 2
        Case 3
        Case 4
            Exit (0)
    $i = 0

Func _CreateMultiKey($key, $cases, $sleep, $return);key to bind, number of options, sleep time between each, return value
    For $x = 0 To $cases Step 1

Return $returnit

I want to take the multi-hotkey code (not from me... someone here wrote it) and be able to make a func of it (_CreateMultiKey)

Basically I want to be able to do something like:

$key = _CreateMultiKey("a", 3, 100, key1)

Which will (hopefully) make a function (while running a script) that binds "a" (hotkeyset) to a function called "key1" with 3 options and 100ms sleep time between each. Then, I want to be able to modify what each option does based on an array stored in "$key" (i.e. if I have 3 options I want it to be like $key[1] $key[2] and $key[3] will control what each does.)

I was thinking of using a for loop and having it read the case number and key and whatever...

Anyway the reason behind this is to put it in an include file and just call it like...

#include <MultiKeys.au3>
$var = _CreateMultiKey("z",3,100,key1)
$var[1] = Sleep(100)
$var[2] = Send("a")
$var[3] = Send("b")

Then when I run the script if I press z once it executes whatever $var[1] is, 2 times for $var[2], etc. I don't know if this is possible but I would appreciate it if anyone can help me with it. Thanks.

(Another reason is that I want to be able to make multiple options of multikey binds when the script is run, based on a GUI or user input or something similar. I.E. Someone uses a GUI to create customizable binds for multiple keys, etc.)


Or possibly have it read a global var for number of functions and have that as the number of options, then when you call it you list what functions you want each to do...?

Edited by darkshadow791

Share this post

Link to post
Share on other sites

AutoIt doesn't support anonymous functions, which is what you're describing. What you could do though, is generate a new .au3 file with FileWriteLine, and then execute it.

Good luck.

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.