ransej

Help on GUI hotkeys or shortcuts

4 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#4 ·  Posted (edited)

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

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

    If _IsPressed("11") And _IsPressed("1") Then
        ; CTRL + Left mouse button pressed
        WinCloseUnderMouse()
    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);
    Else
        ; Didn't find a parent
        $hWnd_found= WinGetTitle($hWnd);
    EndIf

    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)
EndFunc

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

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

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