Sign in to follow this  
Followers 0
sharrakor

How to embed a variable in a function name/hotkeyset

7 posts in this topic

#1 ·  Posted (edited)

I'm trying to make a script that lets the user enter a range of integer values, and for those values, it does something like this:

;the user entered these values
$min=32
$max=56

for i=$min to $i<=$max

func testfunc$i()

send("$i");

endfunc

hotkeyset("{ASC $i}","testfunc$i")

next

Basically it sets a hotkey with that ascii value and creates a function with that in the name. Obviously the real one with do more than this. Can this be done? I want it so that after the loop, if someone presses something like space, it ill call testfunc32().

Edited by sharrakor

Share this post


Link to post
Share on other sites



I'm trying to make a script that lets the user enter a range of integer values, and for those values, it does something like this:

;the user entered these values
$min=32
$max=56

for i=$min to $i<=$max

func testfunc$i()

send("$i");

endfunc

hotkeyset("{ASC $i}","testfunc$i")

next

Basically it sets a hotkey with that ascii value and creates a function with that in the name. Obviously the real one with do more than this. Can this be done? I want it so that after the loop, if someone presses something like space, it ill call testfunc32().

You would use Call() to call a function by string value.

Also, your For loop iteration is not in AutoIt syntax. It should be:

For $i = $min To $max

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm used to C from my classes (mixed the two together), which have given me little time for Autoit. But what I'm interested in doing is initializing a hotkey value and a function within a for loop. Can this be done?

Edited by sharrakor

Share this post


Link to post
Share on other sites

I'm used to C from my classes (mixed the two together), which have given me little time for Autoit. But what I'm interested in doing is initializing a hotkey value and a function within a for loop. Can this be done?

I missed that you were even trying that.

No, you cannot declare functions in a loop or inside any conditional structure (If/EndIf).

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Alright, what about the hotkey thing then? Can I do something like:

for $i=32 to 56

hotkeyset("{ASC $i}","function5")

next

How can I do that? Thanks for the help btw.

Share this post


Link to post
Share on other sites

Alright, what about the hotkey thing then? Can I do something like:

for $i=32 to 56

hotkeyset("{ASC $i}","function5")

next

How can I do that? Thanks for the help btw.

That would be:
HotKeySet(Chr($i), "Function5")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks bro.

:)

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  
Followers 0