AutoHotkey Community

It is currently May 27th, 2012, 9:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: October 19th, 2011, 2:09 am 
Is it possible to use a variable reference in a command? I tried this but it doesn't work.
Code:
MyFunc("MsgBox")

MyFunc(Command) {
   %Command%, hello
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2011, 6:26 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
If I recall this was not possible and changing ahk to make it possible added to much complexity. Someone here may have a useful work around I am not aware of.

The only thing I can think of at the moment is a series of if statements within your function. Clunky, but it might be some help to you.

Code:
MyFunc("MsgBox")

MyFunc(Command) {
  if (Command = "MsgBox")
    MsgBox, hello
  if (Command = "Sleep")
    Sleep, 6000
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2011, 12:31 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
You need AutoHotkey.dll.
Simple as that.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2011, 4:39 pm 
Using a dll file is complicated. Would you mind giving an example?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2011, 4:51 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
There are tons of examples at the documentation

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2011, 5:01 pm 
I'd like to see an example that shows a variable is used in a command name. Thanks.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 10:29 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
Guest,
I found the thread for AHK.DLL. I suggest asking there for help using it dynamically.

http://www.autohotkey.com/forum/topic43049.html

I don't have much of a clue and the help file wouldn't load for me. I figured on trying for a few minutes to see how far I could get, but without a useable help file I'm done for now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 11:42 am 
Offline

Joined: July 10th, 2008, 8:49 am
Posts: 1865
Location: Brussels, Belgium
An other way (actualy I'm already using this way to make "on the fly" command :

Code:
MyFunc("MsgBox", "this is a parameter")

MyFunc(Command, Param) {
    FileAppend %Command% %Param%, TmpScript.ahk
    Run TmpScript.ahk
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 12:38 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
CodeKiller, that solution is not portable (as it only works when AHK is installed) and I politely ask you to let us help the OP with using AutoHotkey.dll, a much better solution which provides many more options to control the dynamic script.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 12:43 pm 
Offline

Joined: July 10th, 2008, 8:49 am
Posts: 1865
Location: Brussels, Belgium
nimda wrote:
CodeKiller, that solution is not portable (as it only works when AHK is installed) and I politely ask you to let us help the OP with using AutoHotkey.dll, a much better solution which provides many more options to control the dynamic script.


???
Did I speak to you ???
Did "Guest" ask for a compiled solution ???
Did I say he MUST use MY solution ???

NO ! He just asked "Is it possible to use a variable reference in a command?"
And I just gave ONE working answer (I didn't even say it is a good one).

So, go to hell ! Thanks !

Have a bad day...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 4:50 pm 
inb4 butthurt flamewar

oh, wait...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 6:39 pm 
Thanks guys. I appreciate your efforts.

I don't mind seeing different solutions but none of you has provided a clear solution that works for me so far.

@CodeKiller the question is not limited to MsgBox. If a command has an outvar, it requires another complicated method to receive the result. Your idea may help some who don't need it to be portable and in non-compiled scripts. So your post is not meaningless.

Overall, it's good to know what I asked is not possible.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 7:02 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
You can do that in AutoHokey_H and AutoHotkey.dll, see my signature.
You will find AhkExported there as well.
Simply copy the appropriate exe from package to a folder and save AutoHotkey.ahk there as well.
Then double click the AutoHotkey.exe to test.

AutoHotkey.ahk:
Code:
#Include <AhkExported>

MyFunc("MsgBox")

MyFunc(Command) {
   static exe:=AhkExported()
   exe.ahkExec(Command ", hello")
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2011, 7:27 pm 
I'll look into it. Thanks.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, hyper_, iBob35555VR, tomoe_uehara and 70 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group