Sunaj Posted March 14, 2007 Posted March 14, 2007 Hi,I have a piece of code that would work most smoothly if I could somehow have the Function() targeted by a GUI menu AND by a hotkey know which one of those items called it. Can it be done? I do have lots of ways that I could work -around- this problem so in case it cannot be done it is no biggie.. Still, I have a feeling I'm missing something stupendously obvious.. Cheers,Sunaj;pseudo code HotKeySet("{ESC}", "fLaunch") GUICtrlCreateMenuitem($yep, $OptionsContext) GUICtrlSetOnEvent($yep, "fLaunch") Func fLaunch() If GUI then x ElseIf Hotkey Then y EndIf EndFunc [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
SadBunny Posted March 14, 2007 Posted March 14, 2007 Hi, I have a piece of code that would work most smoothly if I could somehow have the Function() targeted by a GUI menu AND by a hotkey know which one of those items called it. Can it be done? I do have lots of ways that I could work -around- this problem so in case it cannot be done it is no biggie.. Still, I have a feeling I'm missing something stupendously obvious.. Cheers, Sunaj ;pseudo code HotKeySet("{ESC}", "fLaunch") GUICtrlCreateMenuitem($yep, $OptionsContext) GUICtrlSetOnEvent($yep, "fLaunch") Func fLaunch() If GUI then x ElseIf Hotkey Then y EndIf EndFuncNot sure if this is what you are looking for, but what if you make Func fLaunch ($callType) and make the hotkey call with another parameter than the GUI call? Roses are FF0000, violets are 0000FF... All my base are belong to you.
Sunaj Posted March 15, 2007 Author Posted March 15, 2007 Well, yes, that is what I'm looking for - only thing is that hotkey associated functions and GUICtrlSetOnEvent cannot pass parameters natively (see: http://www.autoitscript.com/forum/index.php?showtopic=15881). So.. not an option (unless I do a workaround). To reiterate: I want to have the Function() targeted by a GUI menu AND by a hotkey know whether a hotkey or a gui item called it..Not sure if this is what you are looking for, but what if you make Func fLaunch ($callType) and make the hotkey call with another parameter than the GUI call? [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
Moderators SmOke_N Posted March 15, 2007 Moderators Posted March 15, 2007 ;pseudo code Opt('GUIOnEventMode', 1) Global $yep = '&Hello', $MenuItem HotKeySet("{ESC}", "fLaunch") $GUI = GUICreate('') GUISetOnEvent(-3, '_ExitNow', $GUI) $OptionsContext = GUICtrlCreateMenu('...') $MenuItem = GUICtrlCreateMenuitem($yep, $OptionsContext) GUICtrlSetOnEvent($MenuItem, "fLaunch") GUISetState() While 1 Sleep(100000) WEnd Func fLaunch() If @HotKeyPressed = '{ESC}' Then MsgBox(64, 'Info', 'Event called Hotkey') Else MsgBox(64, 'Info', 'Event called by GUI') EndIf Return EndFunc Func _ExitNow() Exit EndFunc 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.
Sunaj Posted March 17, 2007 Author Posted March 17, 2007 Hi SmOke_N, - thanks a lot for pointing towards the @HotKeyPressed macro! Sometimes I just stares into the code until blind on the most odd spots! Oh and.. I seriously appreciate the energy you put into helping not just me but seasoned and newbie alike members all across the forum: at the end of it, it is this kinda community spirit that helps make Autoit what is is. GREAT! Cheers, Sunaj ;pseudo code Opt('GUIOnEventMode', 1) Global $yep = '&Hello', $MenuItem HotKeySet("{ESC}", "fLaunch") $GUI = GUICreate('') GUISetOnEvent(-3, '_ExitNow', $GUI) $OptionsContext = GUICtrlCreateMenu('...') $MenuItem = GUICtrlCreateMenuitem($yep, $OptionsContext) GUICtrlSetOnEvent($MenuItem, "fLaunch") GUISetState() While 1 Sleep(100000) WEnd Func fLaunch() If @HotKeyPressed = '{ESC}' Then MsgBox(64, 'Info', 'Event called Hotkey') Else MsgBox(64, 'Info', 'Event called by GUI') EndIf Return EndFunc Func _ExitNow() Exit EndFunc [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
Moderators SmOke_N Posted March 17, 2007 Moderators Posted March 17, 2007 Hi SmOke_N, - thanks a lot for pointing towards the @HotKeyPressed macro! Sometimes I just stares into the code until blind on the most odd spots! Oh and.. I seriously appreciate the energy you put into helping not just me but seasoned and newbie alike members all across the forum: at the end of it, it is this kinda community spirit that helps make Autoit what is is. GREAT!Cheers,SunajThanks... there are many here that do that, and many others that are forming the habit... they all deserve that credit, some more so than myself. 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.
therks Posted March 17, 2007 Posted March 17, 2007 (edited) Are you sure that works? I tried something similar before and if I called the function via the button first it told me that @HotKeyPressed was undefined. *Edit: Well there I go making a fool of myself. It works fine. They must have changed something at some point. Edited March 17, 2007 by Saunders My AutoIt Stuff | My Github
Moderators SmOke_N Posted March 17, 2007 Moderators Posted March 17, 2007 Are you sure that works? I tried something similar before and if I called the function via the button first it told me that @HotKeyPressed was undefined.*Edit: Well there I go making a fool of myself. It works fine. They must have changed something at some point.You could probably manipulate @GUI_CtrlID as well there... I took the path of least resistance 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.
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