Jump to content
Valnurat

Exit GUICtrlCreateInput with a TAB

Recommended Posts

Valnurat

I want to lookup in our AD when I exit a GUICtrlCreateInput don't have focus anymore. I know how to do the lookup in AD, but how to activate something when you exit the GUICtrlCreateInput with a TAB or a mouseclick, so the GUICtrlCreateInput don't have focus anymore, I do not know.

It is the $idInput2 that I need to check if there is a focus or not.

Can someone please help.

Func Main()
    Local $sOU, $sDescription, $dDate
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOKay
                For $id = $idInput1 to $idInput11
                    if GUICtrlRead($id) = '' Then
                        MsgBox(64, "Info", "At least one input is empty.",0,$hGUI)
                        ContinueLoop 2
                    EndIf
                Next
                $sFirst = GUICtrlRead($idInput1)
                $sShort = GUICtrlRead($idInput2)
                $sCountrySite = Stringleft($sShort,4)
                $sOU = Stringleft($sShort,4)
                $sOU = "OU=Consultants,OU=" & StringRight($sOU,2) & ",OU=" & StringLeft($sOU,2) & ",OU=company,DC=AD,DC=company,DC=ORG"
                $sLast = GUICtrlRead($idInput3)
                $sDisp = GUICtrlRead($idInput4)
                For $id = $idRadio1 To $idRadio2
                    If GUICtrlRead($id) = $GUI_CHECKED Then
                        $sDescription = GUICtrlRead($id, $GUI_READ_EXTENDED)
                    EndIf
                Next
                $sEmail = GUICtrlRead($idInput5)
                $sDepart = GUICtrlRead($idInput6)
                $sOffice = GUICtrlRead($idInput7)
                $sManager = GUICtrlRead($idInput8)
                $sMisalCode = GUICtrlRead($idInput9)
                $sTicketNo = GUICtrlRead($idInput10)
                $sCostNo = GUICtrlRead($idInput11)
                $sExtCompe = GUICtrlRead($idInput12)
                $sExtEmail = GUICtrlRead($idInput13)
                If GUICtrlRead($idCheckBox) = $GUI_CHECKED Then
                    $dDate = GUICtrlRead($idDate)
                Else
                    $dDate = _DateAdd('Y',1,_NowCalcDate())
                EndIf
            Case $idCheckBox
                If _IsChecked($idCheckbox) Then
                    GUICtrlSetState($idDate,$gui_enable)
                Else
                    GUICtrlSetState($idDate,$gui_disable)
                EndIf
        EndSwitch
    WEnd
EndFunc

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

Should I understand that the link you sent is for detecting of focus? I would like to find out when a input do not have focus anymore. I would like to do at lookup in out Active Directory.

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

But the links in that link shows when a control get the focus, as I understand it.

The Link JohnOne is pointing to is to google.

 

JohnOne.JPG

 

InunoTaishou  - might point to the correct solution, but I don't know if that exists in AutoIT.

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
AutoBert

when a other control gets focus the old control has lost focus, correct me if i am wrong!

Share this post


Link to post
Share on other sites
Valnurat

True.

I'm not saying that the link is not true. I can't not see the light and maybe it is bad experience of coding.

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
AutoBert

Make a small runable reproducer without AD.

Share this post


Link to post
Share on other sites
Valnurat

I don't know how to make non focus thing, but this should work.

Hopefully.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=test Focus.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>

Global $hGUI, $idInput1, $idInput2

FormCreate()
Main()

Func Main()
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc


Func FormCreate()
; Create a GUI with various controls.
    $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    GUICtrlCreateLabel("Shortname:", 245, 13)
    $idInput1 = GUICtrlCreateInput("", 90, 10, 150, 20)     ; First
    $idInput2 = GUICtrlCreateInput("", 300, 10, 90, 20)     ; Shortname
    GUISetState(@SW_SHOW, $hGUI)
EndFunc

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
kylomas

Valnurat,

This may help...

; *** Start added by AutoIt3Wrapper ***
#include <EditConstants.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=test Focus.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n


Global $hGUI, $idInput1, $idInput2
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')   ; <--- Monitor "command" type messages

FormCreate()
Main()

Func Main()
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Main


Func FormCreate()
    ; Create a GUI with various controls.
    $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    GUICtrlCreateLabel("Shortname:", 245, 13)
    $idInput1 = GUICtrlCreateInput("", 90, 10, 150, 20) ; First
    $idInput2 = GUICtrlCreateInput("", 300, 10, 90, 20) ; Shortname
    GUISetState(@SW_SHOW, $hGUI)

EndFunc   ;==>FormCreate

; this routine will monitor edit notifications.  EN_KILLFOCUS is sent to the parent window every time
; an edit control loses focus.

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $iCtl = BitAND($wParam, 0xFFFF)
    Local $iCode = BitShift($wParam, 16)

    Switch $iCtl
        Case $idInput2
            Switch $iCode
                Case $EN_killfocus
                    ConsoleWrite('$idinput2 just lost focus and it''s value is ' & GUICtrlRead($iCtl) & @CRLF)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_COMMAND

MSDN - https://msdn.microsoft.com/en-us/library/windows/desktop/bb761682(v=vs.85).aspx

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Valnurat

I get some warnings on this.

I tried to declear it and I could compile it, but I don't get any messages in the console.

Capture.JPG


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
AutoBert

Original script from @kylomas is working. The error sounds like you have forgotten a include file.

Share this post


Link to post
Share on other sites
Valnurat

I did a little search and I found a solution.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=test Focus.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>

Global Const $DebugIt = 1
Global $hGUI, $idInput1, $idInput2, $idInput3

GUIRegisterMsg($WM_COMMAND, 'MY_WM_COMMAND')   ; <--- Monitor "command" type messages


FormCreate()
Main()

Func Main()
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc


Func FormCreate()
; Create a GUI with various controls.
    $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    GUICtrlCreateLabel("Last name:", 245, 13)
    GUICtrlCreateLabel("Display name:", 10, 53)
    $idInput1 = GUICtrlCreateInput("", 90, 10, 150, 20)
    $idInput2 = GUICtrlCreateInput("", 300, 10, 90, 20)
    $idInput3 = GUICtrlCreateInput("", 90, 50, 200, 20)
    GUISetState(@SW_SHOW, $hGUI)
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 $idInput1
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Changed"))
                    GUICtrlSetData($idInput3,GUICtrlRead($idInput1))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Setfocus"))
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Killfocus"))
            EndSwitch
        Case $idInput2
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Changed"))
                    GUICtrlSetData($idInput3,GUICtrlRead($idInput2))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Setfocus"))
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input2 Killfocus"))
            EndSwitch
        Case $idInput3
            Switch $nNotifyCode
                Case $EN_CHANGE
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Changed"))
                Case $EN_SETFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 Setfocus"))
                Case $EN_KILLFOCUS
                    If $DebugIt Then ConsoleWrite(_DebugHeader("Input1 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

 

I do now have another small request.

In this exampel I have 3 Inputs. I would like to have input 3 fill out what I type in Input 1 and input 2. Input1 is Firstname and Input3 is Lastname.

I tried to GUICtrlSetData($idInput3,GUICtrlRead($idInput1)) for "Firstname" and that seems to ok. I have the same GUICtrlSetData($idInput3,GUICtrlRead($idInput2)) for "Lastname", but then it will just overwrite what that is already in Input3.

 

I can't see the light in this one, please help.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
AutoBert

Something like this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=test Focus.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>

FormCreate()


Func FormCreate()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Create Consultant")
    GUICtrlCreateLabel("First name:", 10, 13)
    GUICtrlCreateLabel("Last name:", 245, 13)
    GUICtrlCreateLabel("Display name:", 10, 53)
    Local $idInput1 = GUICtrlCreateInput("", 90, 10, 150, 20)
    Local $idInput2 = GUICtrlCreateInput("", 300, 10, 90, 20)
    Local $idInput3 = GUICtrlCreateInput("", 90, 50, 200, 20)
    GUISetState(@SW_SHOW, $hGUI)
    Local $Old3
    ; Loop until the user exits.
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idInput1, $idInput2
                $Old3 = GUICtrlRead($idInput1) & ' ' & GUICtrlRead($idInput2)
                If $Old3 <> GUICtrlRead($idInput3) Then GUICtrlSetData($idInput3, $Old3)
        EndSwitch
    WEnd
EndFunc   ;==>FormCreate

 

Share this post


Link to post
Share on other sites
Valnurat

Yes, like that, but can it be done on the fly in the $EN_CHANGE?


Yours sincerely

Kenneth.

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

  • Similar Content

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • yasha
      By yasha
      i want am trying to select a nimber to run a program and then select where to save the excel result at before hand
      the problem is that it does not save in the folder i want but the folder before any solutions
      #.................
      $sFolder = ""
          ; Create a constant variable in Local scope of the message to display in FileSelectFolder.
          Local Const $sMessage = "Select a folder"
          ; Display an open dialog to select a file.
          $sFileSelectFolder = FileSelectFolder($sMessage, $sFolder)
          If @error Then
              ; Display the error message.
              MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
          Else
              ; Display the selected folder.
              MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
          EndIf
      .......
      ........
      $oExcel = ObjCreate("Excel.Application")                   ; Create an Excel Object
      $oExcel.Visible = 1                                        ; Let Excel show itself
      $oExcel.Workbooks.Open("J:\OPS\OPS_Share\Planners\2 - Weekly Reports\Auto download\"& $YY & $MM & $DD & " ORDER.xls",0)
      $oExcel.ActiveWorkbook.Saveas ( $sFileSelectFolder,""& $YY & $MM & $DD & " ORDER.xlsx", 1)
      $oExcel.ActiveWorkBook.Close
      $oExcel.Quit
      i only want to save it as ddmmyy order inside documents but it saves in libraries as documents ddmmyy order.
×