Jump to content

How Do I Close A Window When Hitting Enter?


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...