Sign in to follow this  
Followers 0
packrat

Why won't my buttons click with the mouse?

11 posts in this topic

I have an AutoIt script that continuously monitors for library staff scanning barcodes. When a barcode is scanned, the data is passed to our integrated library system (separate windows). After displaying the desired data, the staff member can scan another barcode, and so on. If no barcode was scanned (empty textbox) and the ENTER key is pressed, the script exits. Likewise, if the ESC key is pressed, the script exits. There are also two visible buttons which permit the mouse to be used to accomplish these same two actions in place of keystrokes. However...

In the code excerpt below, the "Go" (OK) button and "Exit" (Cancel) button seem inoperational via any kind of mouse click:

Opt("MustDeclareVars", 1) ;like BASIC's "Option Explicit"

AutoItSetOption("WinTitleMatchMode", 4) ; set "advanced" mode for window matching (e.g., classname)
;AutoItSetOption("SendKeyDelay", 100)

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

;####################################################################################
;                            F U N C T I O N S
;####################################################################################

Func GetBarcodeFromUser()
    Local $a
    Local $WinHandle
    Local $txtbox
    Local $OkButton
    Local $CancelButton
    Local $txtbarcode
;
    $WinHandle = GUICreate( "", 410, 23, 292, 18, $WS_POPUP )
        GUISetBkColor(0xCCCCCC)
    ;
        GUICtrlCreateLabel( "Enter barcode:", 2, 4, 750, 28, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black")
        GUICtrlSetColor( -1,0x0000CC)
    ;
        $txtbox = GUICtrlCreateInput( "", 115, 3, 90, 18 )
    ;
        $OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 1200, 0, "Arial Black")
        GUICtrlSetBkColor( -1, 0x00CC00 )
    ;
        GUICtrlCreateLabel( "or press", 235, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0x0000CC )
        GUICtrlCreateLabel( "ESC to stop", 300, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0xEA0000 )
    ;
        $CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 800, 0, "Arial Black" )
        GUICtrlSetBkColor( -1, 0xEE0000 )
    ;
        GUICtrlSetState( $txtbox, $GUI_FOCUS ) ; set focus to enter barcode digits
        GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ) ; enable ENTER key to be equivalent of $OkButton
    GUISetState( @SW_SHOW, $WinHandle ) ; make dialog box visible
;
    WinSetOnTop("[ACTIVE]", "", 1)
;
    $a = 0
    While True ; event loop that waits for entry of barcode
        $a = GUIGetMsg()
        Select
            Case $a = $GUI_EVENT_CLOSE ; Esc key or [X] exit button
                ExitLoop
            Case $a = $CancelButton
                ExitLoop
            ;
            Case $a = $OkButton
                $txtbarcode = GUICtrlRead($txtbox) ; get contents entered in textbox
                If $txtbarcode = "" Then
                    ExitLoop
                Else
                    GUICtrlSetData( $txtbox, "" ) ; clear data entry textbox
                    GUICtrlSetState( $txtbox, $GUI_FOCUS ) ; give focus to textbox
                ; search and display the item record [go to another window here]:
                    MsgBox( 0,"Barcode:", $txtbarcode ) ; substitute command for demo purposes
                ;WinActivate($WinHandle) ; focus on the entry loop [after returning from another window]
                ;WinWaitActive($WinHandle,"",5)
                    GUICtrlSetState( $CancelButton, $GUI_ENABLE ) ; re-enable EXIT button
                    GUICtrlSetState( $OkButton, $GUI_ENABLE ) ; re-enable GO button
                    GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ) ; re-enable ENTER key to be equivalent of $OkButton
                EndIf
            ;
        EndSelect
    Wend
;
    GUIDelete( $WinHandle )
;
EndFunc ; GetBarcodeFromUser


;####################################################################################
;                  M A I N   S U B R O U T I N E
;####################################################################################


;Sleep(3000) ; delay for manually switching between windows

GetBarcodeFromUser()

I'm probably overlooking something elementary, but I just don't see it at the moment. Can anyone help me out? Thanks in advance!

Harvey

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have an AutoIt script that continuously monitors for library staff scanning barcodes. When a barcode is scanned, the data is passed to our integrated library system (separate windows). After displaying the desired data, the staff member can scan another barcode, and so on. If no barcode was scanned (empty textbox) and the ENTER key is pressed, the script exits. Likewise, if the ESC key is pressed, the script exits. There are also two visible buttons which permit the mouse to be used to accomplish these same two actions in place of keystrokes. However...

In the code excerpt below, the "Go" (OK) button and "Exit" (Cancel) button seem inoperational via any kind of mouse click:

. . .

        $OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 1200, 0, "Arial Black")
        GUICtrlSetBkColor( -1, 0x00CC00 )
;
        GUICtrlCreateLabel( "or press", 235, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0x0000CC )
        GUICtrlCreateLabel( "ESC to stop", 300, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0xEA0000 )
;
        $CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 800, 0, "Arial Black" )
        GUICtrlSetBkColor( -1, 0xEE0000 )
;
        GUICtrlSetState( $txtbox, $GUI_FOCUS ); set focus to enter barcode digits
        GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ); enable ENTER key to be equivalent of $OkButton
        GUISetState( @SW_SHOW, $WinHandle ); make dialog box visible

                . . .

I'm probably overlooking something elementary, but I just don't see it at the moment. Can anyone help me out? Thanks in advance!

Harvey

You haven't set any events for the buttons with GUICtrlSetOnEvent

i.e.:

. . .

$OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
GUICtrlSetOnEvent($OKButton, "handling_function_name")

. . .

$CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
GUICtrlSetOnEvent($CancelButton,, "handling_function_name")

. . .
Edited by TheOrignl

Managing the complexities of our daily lives is always our own responsibility; Allowing God to help us and accepting His guidance is our choice. The best choice!

Share this post


Link to post
Share on other sites

You haven't set any events for the buttons with GUICtrlSetOnEvent

i.e.:

. . .

$OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
GUICtrlSetOnEvent($OKButton, "handling_function_name")

. . .

$CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
GUICtrlSetOnEvent($CancelButton,, "handling_function_name")

. . .
@ TheOrignl

he is using GuiGetMsg() so he doesnt have to set events.

@packrat

where you have $a = guigetmsg() try using somethign else then $a like:

$msg = guigetmsg()

then where you have the $a = (a button) switch the $a to $msg

Share this post


Link to post
Share on other sites

where you have $a = guigetmsg() try using somethign else then $a like:

$msg = guigetmsg()

then where you have the $a = (a button) switch the $a to $msg

Changing $a to $msg made no difference in operation. (I don't understand why such a change should have made any difference at all.) Any other ideas?

Harvey

Share this post


Link to post
Share on other sites

My guess would be that your while true loop isn't initiated. Also, I may be mistaken, but if it's not true it passes right by that loop never to return again even when it becomes true again. Would need to see that part of the script.


Giggity

Share this post


Link to post
Share on other sites

I dont know why it wasnt working but I put in guigetcourserinfo and got the button to work

Opt("MustDeclareVars", 1) ;like BASIC's "Option Explicit"

AutoItSetOption("WinTitleMatchMode", 4) ; set "advanced" mode for window matching (e.g., classname)
;AutoItSetOption("SendKeyDelay", 100)

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

;####################################################################################
;                             F U N C T I O N S
;####################################################################################

Func GetBarcodeFromUser()
    Local $a
    Local $WinHandle
    Local $txtbox
    Local $OkButton
    Local $CancelButton
    Local $txtbarcode
    Dim $msg
    Dim $mouse
;
    $WinHandle = GUICreate( "", 410, 23, 292, 18, $WS_POPUP )
        GUISetBkColor(0xCCCCCC)
    ;
        GUICtrlCreateLabel( "Enter barcode:", 2, 4, 750, 28, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black")
        GUICtrlSetColor( -1,0x0000CC)
    ;
        $txtbox = GUICtrlCreateInput( "", 115, 3, 90, 18 )
    ;
        $OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 1200, 0, "Arial Black")
        GUICtrlSetBkColor( -1, 0x00CC00 )
    ;
        GUICtrlCreateLabel( "or press", 235, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0x0000CC )
        GUICtrlCreateLabel( "ESC to stop", 300, 4, 100, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0xEA0000 )
    ;
        $CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 800, 0, "Arial Black" )
        GUICtrlSetBkColor( -1, 0xEE0000 )
    ;
        GUICtrlSetState( $txtbox, $GUI_FOCUS ) ; set focus to enter barcode digits
        GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ) ; enable ENTER key to be equivalent of $OkButton
    GUISetState( @SW_SHOW, $WinHandle ) ; make dialog box visible
;
    WinSetOnTop("[ACTIVE]", "", 1)
;
    $a = 0
    While True ; event loop that waits for entry of barcode
        $msg = GUIGetMsg()
        $mouse = GUIGetCursorInfo($WinHandle)
        
            If $msg = $GUI_EVENT_CLOSE Then; Esc key or [X] exit button
                ExitLoop
            EndIf
            If $msg = $CancelButton Then
                ExitLoop
            EndIf
            if $mouse[2] And $mouse[4] = $OkButton Then
                $txtbarcode = GUICtrlRead($txtbox) ; get contents entered in textbox
                If $txtbarcode = "" Then
                    ExitLoop
                Else
                    GUICtrlSetData( $txtbox, "" ) ; clear data entry textbox
                    GUICtrlSetState( $txtbox, $GUI_FOCUS ) ; give focus to textbox
                ; search and display the item record [go to another window here]:
                    MsgBox( 0,"Barcode:", $txtbarcode ) ; substitute command for demo purposes
                ;WinActivate($WinHandle) ; focus on the entry loop [after returning from another window]
                ;WinWaitActive($WinHandle,"",5)
                    GUICtrlSetState( $CancelButton, $GUI_ENABLE ) ; re-enable EXIT button
                    GUICtrlSetState( $OkButton, $GUI_ENABLE ) ; re-enable GO button
                    GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ) ; re-enable ENTER key to be equivalent of $OkButton
                EndIf
            EndIf
        
    Wend
;
    GUIDelete( $WinHandle )
;
EndFunc ; GetBarcodeFromUser


;####################################################################################
;                   M A I N   S U B R O U T I N E
;####################################################################################


;Sleep(3000) ; delay for manually switching between windows

GetBarcodeFromUser()

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Changing $a to $msg made no difference in operation. (I don't understand why such a change should have made any difference at all.) Any other ideas?

Harvey

The name of the variable is nothing to do with it. You have made your labels too wide and they extend under the buttons. This means that when you click the button the msg will actually be for the label. You either have to disable the labels, which makes the font colours wrong, or keep them away from the buttons.

Opt("MustDeclareVars", 1);like BASIC's "Option Explicit"

AutoItSetOption("WinTitleMatchMode", 4); set "advanced" mode for window matching (e.g., classname)
;AutoItSetOption("SendKeyDelay", 100)

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

;####################################################################################
;                            F U N C T I O N S
;####################################################################################

Func GetBarcodeFromUser()
    Local $a
    Local $WinHandle
    Local $txtbox
    Local $OkButton
    Local $CancelButton
    Local $txtbarcode
;
    $WinHandle = GUICreate( "", 410, 23, 292, 18, $WS_POPUP )
        GUISetBkColor(0xCCCCCC)
  ;
        GUICtrlCreateLabel( "Enter barcode:", 2, 4, 113, 28, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black")
        GUICtrlSetColor( -1,0x0000CC)
  ;
        $txtbox = GUICtrlCreateInput( "", 115, 3, 90, 18 )
  ;
        $OkButton = GUICtrlCreateButton( ">", 208, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 1200, 0, "Arial Black")
        GUICtrlSetBkColor( -1, 0x00CC00 )
  ;
        GUICtrlCreateLabel( "or press", 237, 4, 62, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0x0000CC )
        GUICtrlCreateLabel( "ESC to stop", 300, 4, 89, 18, $SS_LEFTNOWORDWRAP )
        GUICtrlSetFont( -1, 10, 800, 0, "Arial Black" )
        GUICtrlSetColor( -1, 0xEA0000 )
  ;
        $CancelButton = GUICtrlCreateButton( "X", 390, 3, 18, 18, $BS_FLAT )
        GUICtrlSetFont( -1, 8, 800, 0, "Arial Black" )
        GUICtrlSetBkColor( -1, 0xEE0000 )
  ;
        GUICtrlSetState( $txtbox, $GUI_FOCUS ); set focus to enter barcode digits
        GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ); enable ENTER key to be equivalent of $OkButton
    GUISetState( @SW_SHOW, $WinHandle ); make dialog box visible
;
    WinSetOnTop("[ACTIVE]", "", 1)
;
    $a = 0
    While True; event loop that waits for entry of barcode
        $a = GUIGetMsg()
        Select
            Case $a = $GUI_EVENT_CLOSE; Esc key or [X] exit button
                ExitLoop
            Case $a = $CancelButton
                ExitLoop
          ;
            Case $a = $OkButton
                $txtbarcode = GUICtrlRead($txtbox); get contents entered in textbox
                If $txtbarcode = "" Then
                    ExitLoop
                Else
                    GUICtrlSetData( $txtbox, "" ); clear data entry textbox
                    GUICtrlSetState( $txtbox, $GUI_FOCUS ); give focus to textbox
              ; search and display the item record [go to another window here]:
                    MsgBox( 0,"Barcode:", $txtbarcode ); substitute command for demo purposes
              ;WinActivate($WinHandle); focus on the entry loop [after returning from another window]
              ;WinWaitActive($WinHandle,"",5)
                    GUICtrlSetState( $CancelButton, $GUI_ENABLE ); re-enable EXIT button
                    GUICtrlSetState( $OkButton, $GUI_ENABLE ); re-enable GO button
                    GUICtrlSetState( $OkButton, $GUI_DEFBUTTON ); re-enable ENTER key to be equivalent of $OkButton
                EndIf
          ;
        EndSelect
    Wend
;
    GUIDelete( $WinHandle )
;
EndFunc; GetBarcodeFromUser


;####################################################################################
;                  M A I N   S U B R O U T I N E
;####################################################################################


;Sleep(3000); delay for manually switching between windows

GetBarcodeFromUser()
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The problem is this label being to large/long and not allowing the input from the buttons etc

GUICtrlCreateLabel( "Enter barcode:", 2, 4, 750, 28, $SS_LEFTNOWORDWRAP )

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

@ TheOrignl

he is using GuiGetMsg() so he doesnt have to set events.

That's what I get for trying to answer a question while involved in my own script.

The name of the variable is nothing to do with it. You have made your labels too wide and they extend under the buttons. This means that when you click the button the msg will actually be for the label. You either have to disable the labels, which makes the font colours wrong, or keep them away from the buttons.

Thanks for pointing that out martin. As a C programmer trying to come up to speed I appreciate the tip to look out for.


Managing the complexities of our daily lives is always our own responsibility; Allowing God to help us and accepting His guidance is our choice. The best choice!

Share this post


Link to post
Share on other sites

Yes, it never crossed my mind that the (overly-long) labels were masking the buttons, making them seem inoperable. Thanks to everyone for their help and insights!

Harvey

Share this post


Link to post
Share on other sites

The problem is this label being to large/long and not allowing the input from the buttons etc

GUICtrlCreateLabel( "Enter barcode:", 2, 4, 750, 28, $SS_LEFTNOWORDWRAP )

8)

Funny :)


Sorry 4 Bad English, I'm Indonesian...I'm really need 'Translator' for helping me posting in this forum (http://deeriee.wordpress.com)

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