Merrik Posted July 5, 2011 Share Posted July 5, 2011 I have small GUI with a button and I was wondering why it is always the active window. If you open Notepad for example and write a line of text and hit ENTER it then activates my small Autoit GUI. I'm using "HotKeySet("{enter}", "Click_Func") I was hoping the HotKeySet function would only be active when the GUI was the active window on the screen. I'm hoping someone has a solution. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 5, 2011 Moderators Share Posted July 5, 2011 Merrik,I was hoping the HotKeySet function would only be active when the GUI was the active window on the screenAs you have discovered, HotKeys are valid system wide. But do not despair, look at GUISetAccelerators in the Help file and you will learn how to make keys which are only valid when your GUI is active. 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...
Maffe811 Posted July 5, 2011 Share Posted July 5, 2011 (edited) I think you can do something like this: If WinActive($GuiHamdle) then "HotKeySet("{enter}", "Click_Func") Else "HotKeySet("{enter}", "") EndIf Edit: Melba beat me to it Edited July 5, 2011 by Maffe811 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 5, 2011 Moderators Share Posted July 5, 2011 Maffe811,Your solution is also valid, but I feel it would be best to use a flag to show either if the HotKey was set or not or if the GUI was active - otherwise you will be constantly setting/resetting the HotKey as you check the GUI state. Something like this:$fGUI_State = "Active" If WinActive($hGUI) Then If $fGUI_State = "InActive" Then HotKeySet("{enter}", "Click_Func") $fGUI_State = "Active" EndIf Else If $fGUI_State = "Active" Then HotKeySet("{enter}") $fGUI_State = "InActive" EndIf EndIfThis way you only set/reset the HotKey when needed. 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...
Maffe811 Posted July 5, 2011 Share Posted July 5, 2011 You learn stuff when you're trying to help pepole I like this forum [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
Merrik Posted July 5, 2011 Author Share Posted July 5, 2011 Excellent! Thanks guys for the quick responses. 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