Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

How to define a new function


  • Please log in to reply
14 replies to this topic

#1 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 02 July 2006 - 03:42 PM

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







#2 Simucal

Simucal

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 777 posts

Posted 02 July 2006 - 04:10 PM

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)

#3 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 02 July 2006 - 05:39 PM

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.

#4 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,730 posts

Posted 02 July 2006 - 05:41 PM

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.


#5 Simucal

Simucal

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 777 posts

Posted 02 July 2006 - 05:46 PM

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)

#6 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 02 July 2006 - 07:13 PM

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? :D
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

#7 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 03 July 2006 - 09:12 AM

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
:
:



#8 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 03 July 2006 - 01:19 PM

bit hackish. but it works.

AutoIt         
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

#9 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 06 July 2006 - 12:29 PM

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?

#10 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 06 July 2006 - 12:37 PM

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

#11 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 09 July 2006 - 10:07 AM

FileWrite a new .au3 ?

What do u mean?

#12 MHz

MHz

    Just simple

  • MVPs
  • 5,660 posts

Posted 09 July 2006 - 10:46 AM

I'll toss in an example of something like being asked :D 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


#13 Uten

Uten

    stupid is as stupid does..

  • Active Members
  • PipPipPipPipPipPip
  • 1,989 posts

Posted 09 July 2006 - 10:58 AM

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.

#14 sir

sir

    Seeker

  • Active Members
  • 27 posts

Posted 09 July 2006 - 03:21 PM

I'll toss in an example of something like being asked :D 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


#15 MHz

MHz

    Just simple

  • MVPs
  • 5,660 posts

Posted 10 July 2006 - 05:52 AM

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

No, 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. :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users