Sign in to follow this  
Followers 0
slightly_abnormal

How Do I Close A Window When Hitting Enter?

6 posts in this topic

#1 ·  Posted (edited)

I'm making a window, when i hit enter it will close, right now the hotkey is not working because it is globably and it just doesn't work like it should, hitting enter while the window "about" window is active should close it.., if the window is not active then ignore you know like most windows with the okay, or done button..

#include <GUIConstants.au3>
$Form2 = GUICreate("About", 323, 239, 302, 218)
GUISetIcon("D:\006.ico")
$co = GUICtrlCreateGroup("", 8, 8, 305, 185)
$cd = GUICtrlCreatePic("", 16, 24, 105, 97)
GUICtrlCreateLabel("Product Name", 152, 24, 72, 17)
GUICtrlCreateLabel("Version", 152, 48, 39, 17)
GUICtrlCreateLabel("Copyright", 16, 136, 48, 17)
GUICtrlCreateLabel("Comments", 16, 160, 53, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$bt = GUICtrlCreateButton("&OK", 112, 208, 75, 25)
GUISetState(@SW_SHOW)
hotkeyset("{enter}", "_x")

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg =  $bt 
    exit
;;;;;;;
    EndSelect
WEnd
Exit

Func _kill()
    Exit 0
EndFunc

Func _x()
Exit
EndFunc
Edited by slightly_abnormal

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm making a window, when i hit enter it will close, right now the hotkey is not working because it is globably and it just doesn't work like it should, hitting enter while the window "about" window is active should close it.., if the window is not active then ignore you know like most windows with the okay, or done button..

#include <GUIConstants.au3>
$Form2 = GUICreate("About", 323, 239, 302, 218)
GUISetIcon("D:\006.ico")
$co = GUICtrlCreateGroup("", 8, 8, 305, 185)
$cd = GUICtrlCreatePic("", 16, 24, 105, 97)
GUICtrlCreateLabel("Product Name", 152, 24, 72, 17)
GUICtrlCreateLabel("Version", 152, 48, 39, 17)
GUICtrlCreateLabel("Copyright", 16, 136, 48, 17)
GUICtrlCreateLabel("Comments", 16, 160, 53, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$bt = GUICtrlCreateButton("&OK", 112, 208, 75, 25)
GUISetState(@SW_SHOW)
hotkeyset("{enter}", "_x")

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg =  $bt 
    exit
;;;;;;;
    EndSelect
WEnd
Exit

Func _kill()
    Exit 0
EndFunc

Func _x()
Exit
EndFunc
You pretty much answered your own question didn't you?
Func _x()
If WinActive($Form2) Then Exit
EndFunc
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You pretty much answered your own question didn't you?

Func _x()

If WinActive($Form2) Then Exit
EndFunc
Man.. i tried nearly everything, i tried that but it disables enter when a different window is active.. :)

Share this post


Link to post
Share on other sites

Man.. i tried nearly everything, i tried that but it disables enter when a different window is active.. :)

maybe a simple way would be giving the "okay" button focus.. but how?

Share this post


Link to post
Share on other sites

You could always reset the hotkey

#include <GUIConstants.au3>
$Form2 = GUICreate("About", 323, 239, 302, 218)
GUISetIcon("D:\006.ico")
$co = GUICtrlCreateGroup("", 8, 8, 305, 185)
$cd = GUICtrlCreatePic("", 16, 24, 105, 97)
GUICtrlCreateLabel("Product Name", 152, 24, 72, 17)
GUICtrlCreateLabel("Version", 152, 48, 39, 17)
GUICtrlCreateLabel("Copyright", 16, 136, 48, 17)
GUICtrlCreateLabel("Comments", 16, 160, 53, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$bt = GUICtrlCreateButton("&OK", 112, 208, 75, 25)
GUISetState(@SW_SHOW)
HotKeySet('{ENTER}', "_x")

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg =  $bt
    exit
;;;;;;;
    EndSelect
WEnd
Exit

Func _kill()
    Exit 0
EndFunc


Func _x()
    If BitAND(WinGetState($Form2), 8) Then 
        Exit
    Else
        HotKeySet('{ENTER}')
        Send('{ENTER}')
        HotKeySet('{ENTER}', "_x")
    EndIf
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

this is much better! thanks smoke_n once again. :)

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