Sign in to follow this  
Followers 0
FMS

hotkey a buttonpush ???

9 posts in this topic

Hi all.....

When i treid to search the help files for hotkey a buttonpush i could't find it...

maybe somebody knows it iff it even is possible :huh2:

Or is it only to get some functions???

thnx in advanced ;)

(here is simplified what i mean : )

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$Button1 = GUICtrlCreateButton("Button1", 96, 64, 361, 65, $WS_GROUP)
GUISetState(@SW_SHOW, $Form1)
HotKeySet("!c", $Button1);   <-------------------------------------------------- hotkeyset a buttonpush??????

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $GUI = GUICreate("Form2", 133, 154, 192, 114);, Default, Default, $Form1)
            GUISetState(@SW_SHOW, $GUI)
            GUISetState(@SW_DISABLE, $Form1)
            Do
                $nMsg = GUIGetMsg()
            Until $nMsg = $GUI_EVENT_CLOSE
            GUISetState(@SW_ENABLE, $Form1)
            GUIDelete($GUI)
    EndSwitch
WEnd

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



Make a function out of the contents of the $Button1 case. Have the $Button1 case and the HotKeySet run that function. Like this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$Button1 = GUICtrlCreateButton("Button1", 96, 64, 361, 65, $WS_GROUP)
GUISetState(@SW_SHOW, $Form1)
HotKeySet("!c", Function);   <-------------------------------------------------- hotkeyset a buttonpush??????

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Function()
    EndSwitch
WEnd

Func Function()
    $GUI = GUICreate("Form2", 133, 154, 192, 114);, Default, Default, $Form1)
    GUISetState(@SW_SHOW, $GUI)
    GUISetState(@SW_DISABLE, $Form1)
    Do
        $nMsg = GUIGetMsg()
    Until $nMsg = $GUI_EVENT_CLOSE
    GUISetState(@SW_ENABLE, $Form1)
    GUIDelete($GUI)
EndFunc

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

You can also use GUISetAccelerators()

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$Button1 = GUICtrlCreateButton("Button1", 96, 64, 361, 65, $WS_GROUP)
GUISetState(@SW_SHOW, $Form1)

Global $acceleartors[1][2]=[["!c",$Button1]] ;<<<<<<<<<<<<<
GUISetAccelerators($acceleartors,$Form1) ;<<<<<<<<<<<<<

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $GUI = GUICreate("Form2", 133, 154, 192, 114);, Default, Default, $Form1)
            GUISetState(@SW_SHOW, $GUI)
            GUISetState(@SW_DISABLE, $Form1)
            Do
                $nMsg = GUIGetMsg()
            Until $nMsg = $GUI_EVENT_CLOSE
            GUISetState(@SW_ENABLE, $Form1)
            GUIDelete($GUI)
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

thnx somecomputerguy and ahmet,

the thing i was looking for was from ahmet :huh2:

very nice aproach .... also looked further into it thnx for this :ph34r:

do you also know what to do if the fatherGUI is hidden????

because i couldn't find anything on it and it won't work on a hidden GUI... ;)

(that's just what i needed :alien:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$Button1 = GUICtrlCreateButton("Button1", 96, 64, 361, 65, $WS_GROUP)
GUISetState(@SW_HIDE, $Form1);diffrent from last

Global $acceleartors[1][2]=[["!c",$Button1]] ;<<<<<<<<<<<<<
GUISetAccelerators($acceleartors,$Form1) ;<<<<<<<<<<<<<

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $GUI = GUICreate("Form2", 133, 154, 192, 114);, Default, Default, $Form1)
            GUISetState(@SW_SHOW, $GUI)
            GUISetState(@SW_DISABLE, $Form1)
            Do
                $nMsg = GUIGetMsg()
            Until $nMsg = $GUI_EVENT_CLOSE
            GUISetState(@SW_ENABLE, $Form1)
            GUIDelete($GUI)
    EndSwitch
WEnd

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Accelerators only work on the active window, so if it's hidden you can't interact with it that way. You'd need to use the method somdcomputerguy posted, where the hotkey and button both point to the same function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

bummer ;)

thnx for the reply anyway's :huh2:

i treid it that way but couldn't get it working...

in the end i'm making a script whit other functions then that's listed below...

(thnx to melba for a part of this)

i was hoping that a hotkey also was able to call the function "snip"

But this way iff i close the poped up window it kills the hole script....

could somebody point me in the good direction?

;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Animate.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

$hMain_GUI = GUICreate("Test", 615, 438, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
$hRect_Button = GUICtrlCreateButton("Hide father GUI", 3, 3, 184, 37, $WS_GROUP)
$ContextMenu = GuiCtrlCreateContextMenu()
$SubMenu = GuiCtrlCreateMenu("SubMenu", $ContextMenu)
$SubMenuItem = GuiCtrlCreateMenuItem("SubMenu Help", $SubMenu)
$HelpItem = GuiCtrlCreateMenuItem("Hide", $ContextMenu)
$defStyle=GUIGetStyle()
GUISetState(@SW_HIDE)
Opt('MustDeclareVars', 0)

Global $GuiMsg
Global $Show = False
Global $HelpGUI = GUICreate("Help Gui", 500, 200)
Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path, $i

HotKeySet("!z", "ShowGUI")
HotKeySet("!x", "ExitPT")
HotKeySet("!c", "Snip")

_Animate_LoadFromFile(@ScriptDir & '\Images\flag.png')
_Animate_SetDelay(80)
_Animate_ShowIcon()
_Animate_Start()


Global $Show = False

While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $hMain_GUI
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hRect_Button
                    Snip()
            EndSwitch
        Case $hBitmap_GUI
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUICtrlDelete($hBitmap_GUI);GUISetState(@SW_HIDE, $hBitmap_GUI)
            EndSwitch
    EndSwitch

WEnd




Func ShowGUI()
    $Show = Not $Show
    GUISetState($Show, $hMain_GUI)
EndFunc

Func ExitPT()
    Exit
EndFunc

Func Snip()
    GUISetState(@SW_HIDE, $hMain_GUI)
    Mark_Rect()
    $sBMP_Path = ""
    $i = 0
    Do
        $i += 1
        $sBMP_Path = @SCriptDir & "\File" & StringFormat("%02s", $i) & ".bmp"
    Until Not FileExists($sBMP_Path)
    _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False)
    $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100)
    $hPic = GUICtrlCreatePic($sBMP_Path, 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1)
    GUISetState()
EndFunc

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
    GUISetBkColor(0)
    WinSetTrans($hRectangle_GUI, "", 50)
    GUISetState(@SW_SHOW, $hRectangle_GUI)
    GUISetCursor(3, 1, $hRectangle_GUI)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)
        Sleep(10)
    WEnd

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        ; Set in correct order if required
        If $aMouse_Pos[0] < $iX1 Then
            $iX_Pos = $aMouse_Pos[0]
            $iWidth = $iX1 - $aMouse_Pos[0]
        Else
            $iX_Pos = $iX1
            $iWidth = $aMouse_Pos[0] - $iX1
        EndIf
        If $aMouse_Pos[1] < $iY1 Then
            $iY_Pos = $aMouse_Pos[1]
            $iHeight = $iY1 - $aMouse_Pos[1]
        Else
            $iY_Pos = $iY1
            $iHeight = $aMouse_Pos[1] - $iY1
        EndIf

        _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)

        Sleep(10)

    WEnd

    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    EndIf
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp
    EndIf

    GUIDelete($hRectangle_GUI)
    DllClose($UserDLL)

EndFunc

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
    $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
    $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
    $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Shouldn't this - GUICtrlDelete($hBitmap_GUI) be - GUIDelete($hBitmap_GUI)?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

As BrewManNH said... You should use Guidelete() for deleting the child window, also declarate the variable that you use for the child window to avoid errors

alse theres a bug when you capture many screens and the script create many windows.. maybe some algorithm with an array when you create windows will fix that... NOT ALGORITHM AT ALL! :huh2:

here you got!

global $hBitmap_GUI
While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $hMain_GUI
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hRect_Button
                    Snip()
            EndSwitch
        Case else
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIdelete($nMsg[1]);Or GUISetState(@SW_HIDE, $nMsg[1])
            EndSwitch
    EndSwitch
WEnd

PD: Melva23 Rocks i also use his selection box function

EDIT : I also think that if is necesarily declare $hBitmap_GUI or save the Guicreate return in a variable, maybe you can avoid this if you dont gonna use it

Edited by monoscout999

Share this post


Link to post
Share on other sites

thnx alot ;)

now i can work further on this project of mine :alien:

this is what i meant

i learned a little bit more thnx 2u :huh2:


as finishing touch god created the dutch

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