ffunky Posted May 26, 2009 Share Posted May 26, 2009 Hey guys. I created a simple program to sit in my tray and let me do quick margin/markup calculations at work. It works great so far, but I've run into a bug. Well, not really a bug, but I don't know what else to call it. The program sits in the tray and I hit alt+\ to bring it up. I do my calcs and hit Esc and it goes away. However, when I'm in excel or other programs and I try to use the escape key, it doesn't work. It's like the autoit program is stealing my key functionality. Is there a way around this? Like some kind of "if the program is minimized, ignore the escape key" sequence? margin.au3 Link to comment Share on other sites More sharing options...
lordicast Posted May 26, 2009 Share Posted May 26, 2009 (edited) Hotkey remains active once assigned use this in your "While" to only activate it when your programs is running. edit:OOPS while 1 if WinActive('My Program') Then HotKeySet('{ESC}','Function') Else HotKeySet('{ESC}') EndIf sleep(10) WEnd Edited May 26, 2009 by lordicast [Cheeky]Comment[/Cheeky] Link to comment Share on other sites More sharing options...
Levignot Posted May 26, 2009 Share Posted May 26, 2009 Hi, sorry about my english. You can try with HotKeySet("{esc}") Without the method like: HotKeySet("{esc}","methodA") This line put out the HotKeySet, so you can check if your program is @minimized and do something like: Func methodA() if minimized then HotKeySet("{esc}") send("{esc}") sleep(500) HotKeySet("{esc}","methodA") endif endfunc Try something like this, and goodluck! Link to comment Share on other sites More sharing options...
Tec Posted May 26, 2009 Share Posted May 26, 2009 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUIRegisterMsg($WM_ACTIVATEAPP, "_ToggleHotkeys") Global $GUI = GUICreate("Test", @DesktopWidth/2, @DesktopHeight/2, -1, -1, $WS_POPUP) GUISetState() While 1 Sleep( 100 ) WEnd Func _ToggleHotkeys() If WinActive($GUI) Then HotKeySet("{Esc}","_Exit") Else HotKeySet("{Esc}") EndIf EndFunc Func _Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2009 Moderators Share Posted May 26, 2009 ffunky, You need to deregister the HotKey if you want to use it in another program. So activate the HotKey as you wake your program from the taskbar by adding this to the function you call with alt+\:HotKeySet('{ESC}','Your_ESC_Function') Then when you call the function to send your app back to sleep, deregister the HotKey by adding this to Your_ESC_Function:HotKeySet('{ESC}') Now the ESC key will only work when your app is awake. A short example using HOME and END - because it easier to see them work (or not): ;-)#include <GUIConstantsEx.au3> HotKeySet("{HOME}", "My_HOME" ) $hGUI = GUICreate("Test", 500, 500) GUISetState(@SW_HIDE) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func My_HOME() HotKeySet("{END}", "My_END") GUISetState(@SW_SHOW, $hGUI) EndFunc Func My_END() GUISetState(@SW_HIDE, $hGUI) HotKeySet("{END}") EndFunc 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...
AdmiralAlkex Posted May 26, 2009 Share Posted May 26, 2009 It looks to me like you are all overcomplicating it, just use GUISetAccelerators() instead of HotKeySet(). Accelerators are only active on the active window thus solving the problem without any "ugly" fixes (like de-registering hotkeys) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
ffunky Posted May 26, 2009 Author Share Posted May 26, 2009 @Melba23: Thank you very much for the explanation. It worked perfectly! Thanks to everyone else for your suggestions. You are all a great contribution to the AutoIt community! -ffunky Link to comment Share on other sites More sharing options...
ffunky Posted May 26, 2009 Author Share Posted May 26, 2009 It looks to me like you are all overcomplicating it, just use GUISetAccelerators() instead of HotKeySet(). Accelerators are only active on the active window thus solving the problem without any "ugly" fixes (like de-registering hotkeys)That sounds intriguing, AdmiralAlkex. I'll definitely look into that as well. I'm learning quite a bit in the process. Thanks again! Link to comment Share on other sites More sharing options...
Levignot Posted May 26, 2009 Share Posted May 26, 2009 It looks to me like you are all overcomplicating it, just use GUISetAccelerators() instead of HotKeySet(). Accelerators are only active on the active window thus solving the problem without any "ugly" fixes (like de-registering hotkeys)Fantastic, I've got sometimes many problems with the HotKeySet if I run 3 or 4 scripts. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2009 Moderators Share Posted May 26, 2009 AdmiralAlkex, I am not sure Accelerators will work in this case. The app is sent to the tray when not required and I do not believe it can be restored using Accelerators as the GUI is not active. But perhaps you could you provide an example? 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...
AdmiralAlkex Posted May 26, 2009 Share Posted May 26, 2009 @Melba23 As I understood the first post the problem was that hotkeying "esc" would stop if from working in other apps. The OP also said esc would be for minimizing the app, so accelerators is the way to go there. For restoring the app you would still use HotKeySet() since you want to be able to use it anytime. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2009 Moderators Share Posted May 26, 2009 AdmiralAlkex, I think we are both on the same page. Thanks for the clarification. 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