CodeMaster Rapture Posted May 30, 2007 Share Posted May 30, 2007 Hey all,I was messing around with my GUI template and came up with a slick method of enabling/disabling hotkeys depending on the window state:Global Const $WM_ACTIVATEAPP = 0x001C Global Const $GUI_Main_Title = "My GUI 1.00" ;--- Other GUI declarations and creations --- GUIRegisterMsg($WM_ACTIVATEAPP,"_Toggle_Hotkeys") Func _Toggle_Hotkeys($hWnd = 0, $Msg = 0, $wParam = 0, $lParam = 0) ;Parameters are optional If (WinActive($GUI_Main_Title)) Then HotKeySet("{F1}","_Help") HotKeySet("{F2}","_Help_About") HotKeySet("{F3}","_Help_OtherStuff") Else HotKeySet("{F1}","") HotKeySet("{F2}","") HotKeySet("{F3}","") EndIf EndFunc ;==>_Toggle_Hotkeys Func _GUI_Exit() GUIRegisterMsg($WM_ACTIVATEAPP,"") Exit EndFunc ;==>_GUI_Exit While 1 $GUI_Msg = GUIGetMsg() Switch ($GUI_Msg) Case $GUI_EVENT_CLOSE _GUI_Exit() EndSwitch WEndNow, the beauty of this code is that instead of slapping _Toggle_Hotkeys into my main loop, it will only trigger when my GUI is hidden/shown. I do it this way to reduce the number of uneeded function calls I can (thus reducing overhead). If you like, you can just use _Toggle_Hotkeys without the GUIRegisterMsg(), but you'll need to throw it in your main loop somewhere.-CMR Link to comment Share on other sites More sharing options...
FuryCell Posted May 30, 2007 Share Posted May 30, 2007 (edited) Ahh , behold the awesome power of GUIRegisterMsg(). This should prove quite useful until accelerator keys are added to Autoit. Thanks for sharing. Edited May 30, 2007 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
A. Percy Posted May 30, 2007 Share Posted May 30, 2007 Good solution. Thanks! Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator VW Bug user Pinheiral (Pinewood) city: http://pt.wikipedia.org/wiki/Pinheiral Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted May 30, 2007 Share Posted May 30, 2007 Really awesome. Will now have to rewrite some apps. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
CodeMaster Rapture Posted May 31, 2007 Author Share Posted May 31, 2007 I'll be looking into other methods of hotkey setups (i.e. keyboard hooking) that is not as taxing on the CPU. Glad yall enjoy this. -CMR Link to comment Share on other sites More sharing options...
jvanegmond Posted December 3, 2007 Share Posted December 3, 2007 Very awesome. This should be in the helpfile.. #include <GUIConstantsEx.au3> #region GUICreation ; You can discard this region $GUI = GUICreate("Hotkey tester", 200, 100) $Output = GUICtrlCreateLabel("",5,5,190,90) GUISetState() #endregion GUIRegisterMsg(0x001C, "_ToggleHotkeys") ; Register the keys to toggle when something activates or deactives the app.. ; WM_ACTIVATEAPP = 0x001C _ToggleHotkeys() ; Initialise the hotkeys this way #region Main Loop ; You can discard this region While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd #endregion Func _ToggleHotkeys($lHwnd = 0, $lMsg = 0, $wParam = 0, $lParam = 0) ; IMPORTANT FUNCTION If WinActive($GUI) Then HotKeySet("{F5}", "_Function") ; Add more hotkeys here Else HotKeySet("{F5}") ; Add more hotkeys here EndIf EndFunc Func _Function() ; This is a test function, that can be removed GUICtrlSetData($Output, Random(0,10)) EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
DirtDBaK Posted December 3, 2007 Share Posted December 3, 2007 great solution i use IsPressed() but IsPressed() allows you to hold the key down which isnt what i wanted... Nice Idea though... [center][/center] Link to comment Share on other sites More sharing options...
Bert Posted December 4, 2007 Share Posted December 4, 2007 (edited) I do this, which works well, and doesn't tie up the CPU much at all. The example below is what I use for a time stamper / print. It allows for the hotkeyset key to be assigned quickly without much fuss to the function. Func HotKeyFunc() If WinActive("Work Order", "http://www.autoitscripts.com") Then Switch @HotKeyPressed Case "{F9}" $sLongDayName = _DateDayOfWeek(@WDAY) $stamp = _NowTime() $stamp2 = _NowDate() send("---------------------------") Send("{ENTER}") Send(@UserName & ": " & $sLongDayName & " " & $stamp2 & ", " & $stamp & ": ") Case "{PRINTSCREEN}" $active_window = _IEAttach("Work Order") _IEAction($active_window, "printdefault") EndSwitch Else HotKeySet(@HotKeyPressed) Send(@HotKeyPressed) HotKeySet(@HotKeyPressed, "HotKeyFunc") EndFunc EndIf Edited December 4, 2007 by Volly The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Zedna Posted December 4, 2007 Share Posted December 4, 2007 Hey all,I was messing around with my GUI template and came up with a slick method of enabling/disabling hotkeys depending on the window state:Now, the beauty of this code is that instead of slapping _Toggle_Hotkeys into my main loop, it will only trigger when my GUI is hidden/shown. I do it this way to reduce the number of uneeded function calls I can (thus reducing overhead). If you like, you can just use _Toggle_Hotkeys without the GUIRegisterMsg(), but you'll need to throw it in your main loop somewhere.-CMRVERY nice solution. Thanks. I will use it definitelly! Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
arcker Posted December 4, 2007 Share Posted December 4, 2007 i've already used it and it's not necessary to use winactive because in the message, the wparam is for saying ("activate", "desactivate") here is the modified code #include <GUIConstantsEx.au3> #region GUICreation ; You can discard this region $GUI = GUICreate("Hotkey tester", 200, 100) $Output = GUICtrlCreateLabel("",5,5,190,90) GUISetState() #endregion GUIRegisterMsg(0x001C, "_ToggleHotkeys") ; Register the keys to toggle when something activates or deactives the app.. ; WM_ACTIVATEAPP = 0x001C _ToggleHotkeys() ; Initialise the hotkeys this way #region Main Loop ; You can discard this region While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd #endregion Func _ToggleHotkeys($lHwnd = 0, $lMsg = 0, $wParam = 0, $lParam = 0) ; IMPORTANT FUNCTION If $wParam <> 0 Then HotKeySet("{F5}", "_Function") ; Add more hotkeys here Else HotKeySet("{F5}") ; Add more hotkeys here EndIf EndFunc Func _Function() ; This is a test function, that can be removed GUICtrlSetData($Output, Random(0,10)) EndFunc -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
jvanegmond Posted December 4, 2007 Share Posted December 4, 2007 I do this, which works well, and doesn't tie up the CPU much at all. The example below is what I use for a time stamper / print. It allows for the hotkeyset key to be assigned quickly without much fuss to the function. Func HotKeyFunc() If WinActive("Work Order", "http://www.autoitscripts.com") Then Switch @HotKeyPressed Case "{F9}" $sLongDayName = _DateDayOfWeek(@WDAY) $stamp = _NowTime() $stamp2 = _NowDate() send("---------------------------") Send("{ENTER}") Send(@UserName & ": " & $sLongDayName & " " & $stamp2 & ", " & $stamp & ": ") Case "{PRINTSCREEN}" $active_window = _IEAttach("Work Order") _IEAction($active_window, "printdefault") EndSwitch Else HotKeySet(@HotKeyPressed) Send(@HotKeyPressed) HotKeySet(@HotKeyPressed, "HotKeyFunc") EndFunc EndIf The point of this thread is that hotkeys muck up other apps, even when you use the method that you use. For example, when playing a game that blocks simulated input, certain keys simply do not work anymore. The way that is described in this thread prevents that. github.com/jvanegmond Link to comment Share on other sites More sharing options...
jvanegmond Posted December 4, 2007 Share Posted December 4, 2007 i've already used itand it's not necessary to use winactivebecause in the message, the wparam is for saying ("activate", "desactivate")here is the modified codeEven better! github.com/jvanegmond Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted December 6, 2007 Share Posted December 6, 2007 thanks Statism is violence, Taxation is theft. Autoit Wiki 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