SlimShady Posted May 12, 2004 Posted May 12, 2004 I'm creating a Hotkey manager. But I was wondering: Can I add arguments to the the function that hotkeyset would run? If it's not possible can you please add this feature? Thank you.
trids Posted May 12, 2004 Posted May 12, 2004 See this topic for a discussion (and a clever workaround by ScriptKitty )
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 The summary of the workaround in that topic is:Each hotkeyset another function, so I will have to add functions in advance (the opposite function of the script).I will explain what I want to make:The hotkey manager will read hotkeys.ini.It hides itself and sets the hotkeys automatically.Details:In the ini file there is: The hotkey-keys + program to run.For each hotkey, run a program found in the ini file.Scrap of my script:Func SetHotkeys($Count) $Number = $Count + 1 For $i = 1 To $Number $hotkey = IniRead($IniFile, "Hotkeys", "Hotkey" & $i, "") HotKeySet($hotkey, "DoFunction") Next EndFuncSo, when a user presses a certain hotkey, it will run DoFunction().How would the script know which program to run?How would I let the DoFunction() know which hotkey is pressed?
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 (edited) This sucks, I don't want to set 64 static functions.So, there's no other way?Never mind, I will create 15 functions. So, people will be able to set/delete 15 different hotkeys. Edited May 12, 2004 by SlimShady
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 I was thinking about it a lot, and I came to the conclusion there's no way. Well, unless Jon creates the ability to use arguments in HotkeySet. I gave up and created 15 functions.
scriptkitty Posted May 12, 2004 Posted May 12, 2004 remember that functions also change if they have variable, so you could use a cycle, and have 2 hotkeys do several hundred functions. I will use a variation of one key for the example Hotkeyset("{pause}","dosomething") Hotkeyset("!{pause}","cycle"); ALT+Pause cycles and displays it. $x=0 $arrayX=Stringsplit("func1,func2,func3,somethingelse,morejunk,lalala,bob,fred,func9,func10",",") cycle() while 1 sleep(10) wend func cycle() tooltip("") if $x>9 then $x=1 else $x=$x+1 endif tooltip($arrayX[$x],200,0) endfunc func dosomething() msgbox(1,"You could design this to call",$arrayX[$x],5) endfunc so how many would you really need? AutoIt3, the MACGYVER Pocket Knife for computers.
scriptkitty Posted May 12, 2004 Posted May 12, 2004 thinking more on the subject, you could use that INI file, or you could have it pop open an input box and change them in the program itself, and use iniwrite to save changes etc, etc. "Limits are for those with no imagination..." .. scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers.
pekster Posted May 12, 2004 Posted May 12, 2004 (edited) Edit: UBound returns the number of elements. Please note the addition of "-1" after the UBound call from my original post (if you saw it before.)Heh, I didn't see your post scriptkitty until I had already codded this. It's basically a stripped down example of what you mentioned above. I thought I'd share it anyway since I went through the trouble of codding it expandcollapse popup;//// CODE SEGMENT START \\\\ ;put your ini read code here ;for this example I will have $input be an array where $array[0] is an array of hotkeys ;and $array[1] is an array of function names to run ;change to fit your needs #include "funcs.au3";external file that we can edit to include more functions as needed ;script will fail without it, so we should test for its existance before this line ;I was lazy for this stripped script. fix it before you use it. For $i = 0 To UBound($array, 2) - 1 HotKeySet($array[0, $i], $array[1, $i]) Next While 1 Sleep(60000) WEnd ;\\\\ CODE SEGMENT END //// ;//// CODE SEGMENT START \\\\ ;code to add a new hotkey $key = InputBox("New hotkey", "Enter an AutoIt hotkey") $name = InputBox("Hotkey Name", "Please name your hotkey") $file = FileOpenDialog("Select file to run when hotkey pressed", "C:\", "All (*.*)", 1) If not FileExists($file) Then Exit;invalid selection -- may want to notify user instead ;code assumes hotkey and name are valid. please check them with code before this point $funcs = FileOpen(@ScriptDir & "\" & "funcs.au3", 1);open in append mode to add another func If $funcs = -1 Then Exit;error while opening file -- may want to notify user instead FileWriteLine($funcs, "Func " & $name) FileWriteLine($funcs, 'Run("' & $file & '")' ) FileWriteLine($funcs, "Endunc") FileClose($funcs) ;add the values to your ini file with IniWite() here ;change to meet your needs IniWrite($IniFile, "Hotkeys", "Hotkey", $key) IniWtie($IniFile, "Names", "Name", $name) ;\\\\ CODE SEGMENT END ////Edited to correct a minor grammar mistake. Edited May 12, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 (edited) I posted this after I read Scriptkitty's postI forgot about global variables. But it's still not right.You created an array with function names...How would you run the functions when the names (variables) are in an array?The hotkeyset can only run one function. So you will have to create many functions if you have many hotkeys.If you can prove me wrong please post it here.So, I created "many" functions with the example Larry posted.(About 15 functions/hotkeys.)offtopic:I'll create a graphical user interface for all my scripts when AutoItGui is officially released. Currently I list all settings using a loop and display them in a msgbox. Edited May 12, 2004 by SlimShady
scriptkitty Posted May 12, 2004 Posted May 12, 2004 More example. My main question is if you had one hotkey, how would you know what function you wanted to run if more than one? A variable in memory? if so you can build that in. expandcollapse popupHotkeyset("{pause}","dosomething") Hotkeyset("!{pause}","cycle"); ALT+Pause cycles and displays it. $x=0 $arrayX=Stringsplit("func1,func2,func3,somethingelse,morejunk,lalala,bob,fred,func9,func10",",") cycle() while 1 sleep(10) wend func cycle() tooltip("") if $x>9 then $x=1 else $x=$x+1 endif tooltip($arrayX[$x],200,0) endfunc func dosomething() If $x=10 Then call($arrayX[10]); example, this acutally runs func10() Else parms($arrayX[$x]); this will send a parm to a func. EndIf EndFunc Func parms($y) msgbox(1,"You could design this to call",$y,5) EndFunc Func func10() exit EndFunc AutoIt3, the MACGYVER Pocket Knife for computers.
scriptkitty Posted May 12, 2004 Posted May 12, 2004 (edited) Quote The hotkeyset can only run one function. So you will have to create many functions if you have many hotkeys.Maybe, maybe not... You can cycle the hotkey as well as what function that hotkey calls. Hotkeyset("{pause}","func1") Hotkeyset("!{pause}","cycle"); ALT+Pause cycles and displays it. $x=0 $arrayX=Stringsplit("func1,func2,func3",",") cycle() while 1 sleep(10) wend func cycle() tooltip("") if $x>2 then $x=1 else $x=$x+1 endif tooltip($arrayX[$x],200,0) Hotkeyset("{pause}",$arrayX[$x]) endfunc func func1() msgbox(1,"info","Hi, I am func1",5) EndFunc func func2() msgbox(1,"info","Hi, I am func2",5) EndFunc func func3() msgbox(1,"info","Hi, I am func3",5) endfunc edit.. maybe I am just not understanding the question, or the why. But it is fun to think of all that ways you can change it. Edited May 12, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers.
trids Posted May 12, 2004 Posted May 12, 2004 If I read you correctly, Slim, you want to use the INI file to drive a "menu" of hotkeys - each of which will fire up an application corresponding with the hotkey in the INI file .. rather than run through them all sequentially..?If that's so, then that's quite neat, but how is Larry's suggestion (below) inadequate? Larry said: You may have to set up a static 64 functions. I think 64 is the HotKey limit anyhow. Then assign the hotkey to an unassigned function.Func HotKey1();IniRead HotKeyRun1 key here;Run IniRead resultEndFuncFunc HotKey2();IniRead HotKeyRun2 key here;Run IniRead resultEndFuncso, now the magic is in the INI file management.Lar.
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 (edited) That are nice examples. They don't solve this problem:If you want to use a hotkey, the Hotkeyset can't tell a function which hotkey is pressed.As in "an argument". Example of what I would like to have:HotKeySet($hotkey, DoFunction($x))The $x variable will be some value I gave it.And I can use one function that processes every hotkey that's set. Edited May 12, 2004 by SlimShady
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 trids said: If I read you correctly, Slim, you want to use the INI file to drive a "menu" of hotkeys - each of which will fire up an application corresponding with the hotkey in the INI file .. rather than run through them all sequentially..?If that's so, then that's quite neat, but how is Larry's suggestion (below) inadequate?That's a good example. It's not a real problem with the script I'm making now.I gave up already and used Larry's example, but Scriptkitty thought he had the solution .
scriptkitty Posted May 12, 2004 Posted May 12, 2004 Ahh, one func called differently from many hotkeys. I couldn't see the forest for the trees there. need to make 15 functions for 15 variations of the one function. Don't need 15 hotkeys nessasarly, but would need 15 different functions for 15 seperate keys. example: func runthis($x) run($x) endfunc AutoIt3, the MACGYVER Pocket Knife for computers.
CyberSlug Posted May 12, 2004 Posted May 12, 2004 Question for developers: Would it be possible to create a macro, say @HotKey, that returns the value (string representation) of the most recently pressed hotkey? If so, we could do something like: HotKeySet"{Esc}" ,"keyHandler") HotKeySet"{Pause}" ,"keyHandler") Func keyHandler() Select Case @HotKey = "{Esc}" MsgBox(4096,"", "you pressed Escape." Case @HotKey = "{Pause}" MsgBox(4096,"", "you pressed Pause." EndSelect Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
SlimShady Posted May 12, 2004 Author Posted May 12, 2004 No, sorry, still not the solution.That runthis($x)...I can't do HotKeyset($Keys, "runthis($x)" ...I will have to accept that I have to create multiple functions for multiple Hotkeys.
pekster Posted May 12, 2004 Posted May 12, 2004 Another complex issue that arrises is the dynamic ability of his script. From what I understand SlimShady, you want the ability to add in additional hotkeys and programs through this script. Since each function needs to be defined by itself, you need to edit some kind of AU3 file when a new function is created (like my example above.) Without this, you would have to edit the source of your main program whenever you wanted to add in a new hotkey that referanced to a new function. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.
scriptkitty Posted May 12, 2004 Posted May 12, 2004 (edited) Actually I was thinking of generic functions that are defined in the script by an array: $arrayX=Stringsplit("bob,fred,sam,ect",",") ; bunch of code hotkeyset("{pause}","func1"); just an example hotkeyset("!{pause}","func2"); just one more example while 1 sleep(10) wend func dosomething($x) msgbox(1,"display", $x) endfunc func func1() dosomething($arrayX[1]) endfunc func func2() dosomething($arrayX[2]) endfunc func func3() dosomething($arrayX[3]) endfunc func func4() dosomething($arrayX[4]) endfunc You could make up say 50 generic functions that would actually be defined by the array. That array could be read from a text file, ini, ect. In this example, I made 4 functions, but only used 2 of them. They both use the same fund dosomething() To make it easier to type all these functions in: hotkeyset("{pause}","start") WinWait("(*#$&") Func start() For $i=1 To 10; change this to how many you want send("func func"&$i&"(){enter}") send("dosomething($arrayX["&$i&"]){enter}") send("{home}endfunc{enter}") Next EndFunc Edited May 12, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers.
SlimShady Posted May 13, 2004 Author Posted May 13, 2004 Ok, nice. I'll save all these examples until I need them. I almost finished my Hotkey Manager. You will be able to either run a command or choose a program for each hotkey.
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