Sign in to follow this  
Followers 0
ffunky

Escape key too powerful...

12 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0