sir Posted July 2, 2006 Posted July 2, 2006 I just want to define functions from string arrays. Example: I have an array $varKey[] . The value may be $varKey[1]="ddd",.... How can I write an autoit script Dim $varKey[3] For $i = 1 To 3 Func $varKey[$i]() Send($i) EndFunc Next
Simucal Posted July 2, 2006 Posted July 2, 2006 You have some serious flaws in your script. Here is an example I wrote up real fast to show you a simple script that sends each element in the array. It has a "function" that does this, but it isnt needed... simply included it because you asked. $varKey = StringSplit("Apple,Orange,Pear,Peach,Tomato", ",") ; Create an array with fruit names as each element Run("notepad.exe") ; Lets open notepad so you can see this script send each element of the array. WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") For $i = 1 to UBound($varKey) - 1 ; Execute the SendArray function for each element of the array, until the array ends SendArray($varKey[$i]) Next Func SendArray($s_Temp) ; Simple function that sends what text it is given. This function is useless however, you could just include this send() in your for loop. Send($s_Temp&@CRLF) EndFunc AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
sir Posted July 2, 2006 Author Posted July 2, 2006 Thx Simucal. but what i need is to make new shortkey program eg. the program will type "dogoooo" when i press "ctrl+d" etc.. That means I want define the function from array loaded from the INI file first, then the function will start when i press a shortkey.
Moderators SmOke_N Posted July 2, 2006 Moderators Posted July 2, 2006 Thx Simucal. but what i need is to make new shortkey program eg. the program will type "dogoooo" when i press "ctrl+d" etc.. That means I want define the function from array loaded from the INI file first, then the function will start when i press a shortkey.Look at HotKeySet(). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Simucal Posted July 2, 2006 Posted July 2, 2006 Thx Simucal. but what i need is to make new shortkey program eg. the program will type "dogoooo" when i press "ctrl+d" etc.. That means I want define the function from array loaded from the INI file first, then the function will start when i press a shortkey.That isnt ANYWHERE near what you said in your first post. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
PsaltyDS Posted July 2, 2006 Posted July 2, 2006 Thx Simucal. but what i need is to make new shortkey program eg. the program will type "dogoooo" when i press "ctrl+d" etc.. That means I want define the function from array loaded from the INI file first, then the function will start when i press a shortkey. The smart people may have followed that, but I'm lost. Can you post a sample of what the .ini file would contain? Something like: ; Shortcuts.ini [Shortcuts] a="ardvarkooo" b="batoooo" c="catoooo" d="dogoooo" e="elephantoooo" Or however you have it formatted? 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
sir Posted July 3, 2006 Author Posted July 3, 2006 The ini file will look like ; shortkey.ini [shortcuts]a="ardvarkooo" b="batoooo" c="catoooo" d="dogoooo" e="elephantoooo" [key] a="!p" b="!w" c="^y" d="!^i" e="^j" the au3 file is as $varKey = IniReadSection(".\shortkey.ini", "key") If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $varKey[0][0] HotKeySet( $varKey[$i][1] , $varKey[$i][0] ) Next EndIf Then I want to define function like Func a() Send("ardvarkooo") EndFunc : :
w0uter Posted July 3, 2006 Posted July 3, 2006 bit hackish. but it works. Global $varKey = IniReadSection(".\pr0n.ini", "key") If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $varKey[0][0] HotKeySet($varKey[$i][1], "_Handle") Next EndIf While 1 Sleep(10) WEnd Func _Handle() For $i = 1 To $varKey[0][0] If $varKey[$i][1] = @HotKeyPressed Then Return _Key(IniRead(".\pr0n.ini", "Shortcuts", $varKey[$i][0], 0)) Next EndFunc ;==>_Handle Func _Key($s_val) ConsoleWrite($s_val & @LF) EndFunc ;==>_Key ; shortkey.ini [Shortcuts] a=ape b=bat c=cat d=dog e=elephant [key] a=!a b=!b c=!c d=!d e=!e My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
sir Posted July 6, 2006 Author Posted July 6, 2006 Thank you very much! Now I can create my shortkey program. Go back to the original topic title. Does any one know how to define function from an string array?
w0uter Posted July 6, 2006 Posted July 6, 2006 FileWrite a new .au3 ? My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
MHz Posted July 9, 2006 Posted July 9, 2006 I'll toss in an example of something like being asked as I am not exactly sure of the question. Global $varKey[3] $varKey[0] = '_func00' $varKey[1] = '_func01' $varKey[2] = '_func02' For $i = 0 To UBound($varKey) - 1 Call($varKey[$i]) Next Func _func00() MsgBox(0, '', '00') EndFunc Func _func01() MsgBox(0, '', '01') EndFunc Func _func02() MsgBox(0, '', '02') EndFunc
Uten Posted July 9, 2006 Posted July 9, 2006 I'm not sure either but I think your looking for somthing as described in this thread. Have your script write the "plugin" on the fly. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
sir Posted July 9, 2006 Author Posted July 9, 2006 I'll toss in an example of something like being asked as I am not exactly sure of the question. Global $varKey[3] $varKey[0] = '_func00' $varKey[1] = '_func01' $varKey[2] = '_func02' For $i = 0 To UBound($varKey) - 1 Call($varKey[$i]) Next Func _func00() MsgBox(0, '', '00') EndFunc Func _func01() MsgBox(0, '', '01') EndFunc Func _func02() MsgBox(0, '', '02') EndFunc Sorry for my bad english. You r approaching my question. From your code, I just want to know whether there are another way to define function from $varKey[3] array directly. For example (this not work) Func $varKey[1]() MsgBox(0, '', '00') EndFunc
MHz Posted July 10, 2006 Posted July 10, 2006 Sorry for my bad english. You r approaching my question. From your code, I just want to know whether there are another way to define function from $varKey[3] array directly. For example (this not work) Func $varKey[1]() MsgBox(0, '', '00') EndFuncNo, you cannot directly use a variable or an array as a function name like you display. If you want to try something different, then you would have to rewrite your script on the fly and run that. Similar to as Uten is suggesting as an alternative to try to make you idea happen.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now