LittleHuba Posted March 7, 2011 Share Posted March 7, 2011 Hey I'm writing a script to start other progs with hotkeys. for my script I need to set a hotkey for a function. Thats no big problem. HotkeySet( "{F10}", "Hotkeyexecute") Its like this code. But for my script I need to send a variable to the function. This variable depends to the pressed key. I tested this code: HotkeySet( $hotkey, "Hotkeyexecute($arraynumber)") And this one: HotkeySet( $hotkey, "Hotkeyexecute("&$arraynumber&")") But when I start the script and press the comination, set in $hotkey nothing happens. It only works with this code: HotkeySet( $hotkey, "Hotkeyexecute") There isn't a error set or something else. Please help me. Link to comment Share on other sites More sharing options...
jvanegmond Posted March 7, 2011 Share Posted March 7, 2011 (edited) HotKeySet second parameter only takes a reference to a function name, which is used to find the function to call. You can not pass an entire line of script to the function. Furthermore, HotKeySet can only call functions that don't need any parameters, either because the function has no parameters or all the parameters have default values and are therefore optional.Your problem however is a valid one and it needs to be solved in some way. AutoIt has chosen to do this by offering a @HotKeyPressed macro which can be used inside a function that handles a hotkey press. An example of this is:For $i = 1 To 12 HotKeySet("{F" & $i & "}", "MyHotkeyHandler") Next While 1 Sleep(500) WEnd Func MyHotkeyHandler() $key = @HotKeyPressed MsgBox(0, "", "You pressed: " & $key) EndFuncAlternatively, you can define functions for each key. An example again:For $i = 1 To 12 HotKeySet("{F" & $i & "}", "HandlerForF" & $i) Next While 1 Sleep(500) WEnd Func HandlerForF1() EndFunc Func HandlerForF2() EndFuncThis last approach also fits with the approach that AutoIt takes, but yet it is not fully supported. For example, binding a HotKey to a non-existant function is not detected by Au3Check and it will not cause the script to hard-crash. Even though there is no way for the script to ever resolve that function during the course of the program (all functions must be known at compile-time, but functions via HotKey are bound at runtime). This is inconvenient for the programmer because it leads to (almost) silent errors, which truth be told, no one ever checks. Therefore, I recommend that you use the first option with @HotKeyPressed. Edited March 7, 2011 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
LittleHuba Posted March 7, 2011 Author Share Posted March 7, 2011 Hey thanks for the help!!! The first solution was the best one. I had to rewrite the whole script, but now it works. AutoIt should change something in this function. LittleHuba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2011 Moderators Share Posted March 7, 2011 LittleHuba,AutoIt should change something in this functionAre you volunteering to write the code? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
martin Posted March 7, 2011 Share Posted March 7, 2011 LittleHuba,Are you volunteering to write the code? M23Well there is no need because I did it some time ago .The UDF is in my signature and it can be used for passing parameters to functions for HotKeySet, GuiCtrlSetOnEvent and GuiSetOnEvent. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2011 Moderators Share Posted March 7, 2011 martin,Well, in truth I did I not really think the OP ever would, so it is just as well that you have! I forgot your UDF dealt with HotKeys - I only ever use it for functions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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