doestergaard

Disable hotkeys when child GUI is active?

4 posts in this topic

#1 ·  Posted (edited)

Hi

I have created a form (main gui) which reads user inputs. From time to time, the user may need to set additional settings for the program, which is hidden because it doesn't make sense to put that on the main gui. Im therefore trying to create a child gui, which is activated by CTRL+S, but I only want that shortcut to be active, while the main gui is active.

The problem is, that the HotKey gets bound so CTRL+S will not work in other applications. Also, the CTRL+S is not disabled when the ShowChildGUI is called.

My question is how i can disable the CTRL+S hotkey while the child gui is shown, and reenable it, when the main gui takes back focus.

 

Thanks in advance :)

Here is the example: (note: only for illustration)

Opt("GUIOnEventMode", 1)

#include <GUIConstants.au3>

Global Const $WM_ACTIVEAPP = 0x001C
Global $hGUIMain, $hGUIChild

GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys")

; Parent GUI
$hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1)
GUISetState(@SW_SHOW, $hGUIMain)

; Child GUI
$hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1)

While 1
    Sleep(10)
WEnd

Func ShowChildGUI()
    GUISetState(@SW_DISABLE, $hGUIMain)
    GUISetState(@SW_SHOW, $hGUIChild)
EndFunc

Func HotKeys()
    If WinActive($hGUIMain) Then
        HotKeySet("^{s}", "ShowChildGUI")
    Else
        HotKeySet("^{s}")
    EndIf
EndFunc

 

Edited by doestergaard

Share this post


Link to post
Share on other sites



Okay, i found out, that in my program, the child GUI is actually getting created in the ShowChildGUI function, so multiple instances of the child gui is created when the hotkey is activated.

Can it be, that you have to create the child gui outside ShowChildGUI and just call the SetState() function when the HotKey is activated?

 

Hope it makes sense :P

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Okay, it seems that the ChildGUI is not active, unless i click on it in the taskbar. I put in a MsgBox to show when the Child GUI was the active Windows, but it isn't unless i click on it in the taskbar.

The weird thing is though, if I use ConsoleWrite to output which windows is active, it outputs the Child GUI? :s But the MsgBox doesn't show until i click on the child gui windows in the taskbar:

Opt("GUIOnEventMode", 1)

#include <GUIConstants.au3>

Global Const $WM_ACTIVEAPP = 0x001C
Global $hGUIMain, $hGUIChild

GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys")

; Parent GUI
$hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1)
GUISetState(@SW_SHOW, $hGUIMain)

; Child GUI
$hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1)

While 1
    Sleep(10)
WEnd



Func ShowChildGUI()
    GUISetState(@SW_DISABLE, $hGUIMain)
    GUISetState(@SW_SHOW, $hGUIChild)

    $handle = WinGetHandle("[ACTIVE]")
 
    ConsoleWrite("Title: " & WinGetTitle($handle) & @CRLF) ; outputs: ChildGUI
    ConsoleWrite("Process: " & WinGetProcess($handle) & @CRLF) ; outputs: 3568
EndFunc

Func HotKeys()
    If WinActive($hGUIMain) Then
        HotKeySet("^{s}", "ShowChildGUI")
    ElseIf WinActive($hGUIChild) Then
        MsgBox(64, "Message", "Child GUI is the active window", 0)
    Else
        HotKeySet("^{s}")
    EndIf
EndFunc

 

Edited by doestergaard

Share this post


Link to post
Share on other sites

Here is another way, using GUISetAccelerators (CTRL+S = show the child window, CTRL+h = hide the child window) :

Opt("GUIOnEventMode", 1)

#include <GUIConstants.au3>

Global Const $WM_ACTIVEAPP = 0x001C
Global $hGUIMain, $hGUIChild

; GUIRegisterMsg($WM_ACTIVEAPP, "HotKeys")

; Parent GUI
$hGUIMain = GUICreate("MainGUI", 579, 457, -1, -1)
$idDummyShow = GUICtrlCreateDummy()
GUICtrlSetOnEvent($idDummyShow, "ShowChildGUI")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

Local $aKeysMain = [["^s", $idDummyShow]]
GUISetAccelerators($aKeysMain)

GUISetState(@SW_SHOW, $hGUIMain)



; Child GUI
$hGUIChild = GUICreate("ChildGUI", 412, 240, -1, -1)
$idDummyHide = GUICtrlCreateDummy()
GUICtrlSetOnEvent($idDummyHide, "HideChildGUI")

Local $aKeysChild = [["^h", $idDummyHide] ]
GUISetAccelerators($aKeysChild)

While 1
    Sleep(10)
WEnd

Func ShowChildGUI()
    ConsoleWrite("show" & @CRLF)
    GUISetState(@SW_DISABLE, $hGUIMain)
    GUISetState(@SW_SHOW, $hGUIChild)   
EndFunc


Func HideChildGUI()
    ConsoleWrite("hide" & @CRLF)
    GUISetState(@SW_ENABLE, $hGUIMain)
    GUISetState(@SW_HIDE, $hGUIChild)
EndFunc


Func _Quit()
    Exit
EndFunc

 

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