Jump to content

Help on GUI hotkeys or shortcuts

Recommended Posts


Ok, so ive made a gui that has start button and will do a specific task like, it will automatically move the cursor and do other stuff on a different window and will take some time to stop, i wanted to make a hotkey/shortcuts to make it stop even the focus window is in notepad, please help

Share this post

Link to post
Share on other sites

@ransej so you want to make a hot key, did you search in the help file? Look at HotKeySet, which should do exactly what you're after. If you read through that entry in the help file, you'll even find not one but two examples on how to use it.

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

yes i would like to make a hotkey for making the gui to stop, when my cursor moves to an out of place position, ive tried the example it only works on script, not on the gui.exe something

Share this post

Link to post
Share on other sites

First we find what window is under mouse cursor.  Then we close it?

Two Hotkey methods here: The _IsPressed and the HotKeySet

#include <WinAPI.au3>; _WinAPI_GetMousePos, _WinAPI_WindowFromPoint, _WinAPI_GetParent
#include <GUIConstants.au3>; GUI_EVENT_CLOSE
#include <Misc.au3>; _IsPressed
#include <MsgBoxConstants.au3>; $MB_YESNOCANCEL, $IDYES

$hGui = GUICreate("Get Window Under Mouse", 320, 200)
GUICtrlCreateLabel( "Press CTRL + K or" & @CRLF & _
                    "Press CTRL + Left Mouse Button to close window under mouse", 5, 25, 320, 50)
GUISetState(); show the gui

HotKeySet("^k", "WinCloseUnderMouse"); CTRL + K

    ; Get window messages such as the Close Button
    $msg = GUIGetMsg()

    If _IsPressed("11") And _IsPressed("1") Then
        ; CTRL + Left mouse button pressed
    EndIf;get window title

Until $msg = $GUI_EVENT_CLOSE

Func WinUnderMouse()
    $pos= _WinAPI_GetMousePos()
    $hWnd= _WinAPI_WindowFromPoint($pos)
    ; Get parent window
    $phWnd= _WinAPI_GetParent($hWnd)

    If $phWnd > 0 Then
        ; Found a parent
        $hWnd_found= WinGetTitle($phWnd);
        ; Didn't find a parent
        $hWnd_found= WinGetTitle($hWnd);

    Return $hWnd_found
EndFunc; WinGetUnderMouse

Func WinCloseUnderMouse()
    $hWnd= WinUnderMouse()
    $rc= MsgBox($MB_YESNOCANCEL, "Verify", "Window Title: " & @CRLF & WinGetTitle($hWnd) & @CRLF & "Close Window, Correct?", 0, $hGui)
    ; Close the window
    If $rc = $IDYES Then WinClose($hWnd)

EDIT: Updated to use handles found to avoid logical error of more then one window title match :)

We could try a process suspend, if you wanted to simply pause the GUI under mouse.

Edited by Xandy

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