Sign in to follow this  
Followers 0
JohnBailey

_Pressed - Most Efficient Way

3 posts in this topic

Here's my script. If you run it or just look through it you should be able to see what I'm wanting to do. However, I think this method is very inefficient!

I don't like that there is a separate function for each button.

#include <GUIConstants.au3>
#Include <Misc.au3>

If Not IsDeclared('WM_COMMAND') Then        Global Const $WM_COMMAND    = 0x0111
If Not IsDeclared('EN_CHANGE') Then     Global Const $EN_CHANGE = 0x300
If Not IsDeclared('EN_SETFOCUS') Then   Global Const $EN_SETFOCUS = 0x100
If Not IsDeclared('EN_KILLFOCUS') Then  Global Const $EN_KILLFOCUS = 0x200
Global Const $DebugIt = 1
    
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 450, 156, 193, 125)
$Button1 = GUICtrlCreateButton("Go", 319, 37, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 46, 39, 262, 21)
$Button2 = GUICtrlCreateButton("Go", 317, 89, 75, 25, 0)
$Input2 = GUICtrlCreateInput("", 46, 91, 262, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE,'_GUIEvents')

GUICtrlSetOnEvent($Button1,'Button1')
GUICtrlSetOnEvent($Button2,'Button2')

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

Global $ControlID

While 1
    Sleep(100)
    If WinActive('Form1') Then
        If _IsPressed ('0D') Then
            Call($ControlID)
            If $DebugIt Then ConsoleWrite(_DebugHeader("EnterKey Pressed"))
        EndIf
    EndIf
WEnd

Func Button1()
    MsgBox(0,'Msg',GUICtrlRead($Input1))
EndFunc
Func Button2()
    MsgBox(0,'Msg',GUICtrlRead($Input2))
EndFunc


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
   ; gaFrost for monitoring inputfield change
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam

    Switch $nID
        Case $Input1
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Changed"))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Setfocus"))
                    $ControlID = 'Button1'
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Killfocus"))
            EndSwitch
        Case $Input2
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Changed"))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Setfocus"))
                    $ControlID = 'Button2'
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Killfocus"))
            EndSwitch
    EndSwitch
   ; Proceed the default Autoit3 internal message commands.
   ; You also can complete let the line out.
   ; !!! But only 'Return' (without any value) will not proceed
   ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_COMMAND

;===============================================================================
; Function Name:    _DebugHeader
; Description:      Gary's console debug header.
; Parameter(s):         $s_text      - IN -
;
; Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):
; Note(s):
;===============================================================================
Func _DebugHeader($s_text)
    Return _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF
EndFunc  ;==>_DebugHeader

Func _GUIEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Terminate()
    EndSelect
EndFunc  ;==>_GUIEvents

Func OnAutoItExit()
    ConsoleWrite('CLOSED via Exit'&@CRLF)
EndFunc

Func Terminate()
    ConsoleWrite('CLOSED via Terminate'&@CRLF)
    Exit
EndFunc

A decision is a powerful thing

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>
#Include <Misc.au3>

;If Not IsDeclared('WM_COMMAND') Then         Global Const $WM_COMMAND     = 0x0111
;If Not IsDeclared('EN_CHANGE') Then     Global Const $EN_CHANGE = 0x300
;If Not IsDeclared('EN_SETFOCUS') Then     Global Const $EN_SETFOCUS = 0x100
;If Not IsDeclared('EN_KILLFOCUS') Then     Global Const $EN_KILLFOCUS = 0x200
Global Const $DebugIt = 1
    
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 450, 156, 193, 125)
$Button1 = GUICtrlCreateButton("Go", 319, 37, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 46, 39, 262, 21)
$Button2 = GUICtrlCreateButton("Go", 317, 89, 75, 25, 0)
$Input2 = GUICtrlCreateInput("", 46, 91, 262, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE,'_GUIEvents')

GUICtrlSetOnEvent($Button1,'Button')
GUICtrlSetOnEvent($Button2,'Button')

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

Global $ControlID

While 1
    Sleep(100)
    If WinActive('Form1') Then
        If _IsPressed ('0D') Then
            Call($ControlID)
            If $DebugIt Then ConsoleWrite(_DebugHeader("EnterKey Pressed"))
        EndIf
    EndIf
WEnd

Func Button1()
    MsgBox(0,'Msg',GUICtrlRead($Input1))
EndFunc
Func Button2()
    MsgBox(0,'Msg',GUICtrlRead($Input2))
EndFunc
Func Button()
    MsgBox(0,'Msg', @GUI_CtrlId)
EndFunc

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
   ; gaFrost for monitoring inputfield change
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam

    Switch $nID
        Case $Input1
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Changed"))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Setfocus"))
                    $ControlID = 'Button1'
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Killfocus"))
            EndSwitch
        Case $Input2
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Changed"))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Setfocus"))
                    $ControlID = 'Button2'
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Killfocus"))
            EndSwitch
    EndSwitch
   ; Proceed the default Autoit3 internal message commands.
   ; You also can complete let the line out.
   ; !!! But only 'Return' (without any value) will not proceed
   ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_COMMAND

;===============================================================================
; Function Name:    _DebugHeader
; Description:        Gary's console debug header.
; Parameter(s):            $s_text         - IN -
;
; Requirement(s):
; Return Value(s):
; User CallTip:
; Author(s):
; Note(s):
;===============================================================================
Func _DebugHeader($s_text)
    Return _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF
EndFunc  ;==>_DebugHeader

Func _GUIEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Terminate()
    EndSelect
EndFunc  ;==>_GUIEvents

Func OnAutoItExit()
    ConsoleWrite('CLOSED via Exit'&@CRLF)
EndFunc

Func Terminate()
    ConsoleWrite('CLOSED via Terminate'&@CRLF)
    Exit
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks Valuater!! So basically the way I was doing it is the best way?


A decision is a powerful thing

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