OldGuyWalking

Dummy Control Not Triggering

4 posts in this topic

I wanted a quick way to identify screen coordinates and created a simple form.  I also wanted to collect the information. Goal was to move the mouse to different locations, hit a key combination and have the program  collect info for that position and write it to a file.

I couldn't use a button on the form and HotKeys was not recommended (according to some posts I'd read on here).

I discovered GUIAccelerators but I'm stuck on what triggers the accelerator key.  I've looked at the help file for GUISetAccelerators which references GUICtrlCreateDummy and used the code from both of those.  I'm not getting any errors and everything seems to run okay except when I press Ctrl + [F3] nothing is captured. 

This is a work in progress so there's extra code that I haven't cleaned up yet.

Any help would be appreciated. 

Bill

; Displays the Window Handle, Window Text, Control Handle, and mouse position.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=Y
#AutoIt3Wrapper_Res_Comment=Show screen coordinates.
#AutoIt3Wrapper_Res_Description=Show screen coordinates.
#AutoIt3Wrapper_Res_Fileversion=0.0.0.1
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

Global $Debug = 0

Dim $sWinTitle
Dim $sWinText
Dim $sWinHnd
Dim $sWinCtrlRef
Dim $sWinCtrlText
Dim $sWinCtrlHnd
Dim $aPos
Dim $mPos
Dim $sMousePos
Dim $sControlPos
Dim $iFile
Dim $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log"
Dim $sReport

; HotKeySet("!{Esc}", "Terminate")
; HotKeySet("!{F3}", "WriteLogFile")

#Region ### START Koda GUI section ### Form=F:\AutoIT Apps\Misc Mini Utilities\Coordinates\Coordinates.kxf
Global $Coordinates = GUICreate("Coordinates", 340, 225, 1, 750, -1, $WS_EX_TOPMOST)
Global $lblXPos = GUICtrlCreateLabel("XPos:", 7, 16, 39, 20, $SS_RIGHT)
Global $XPos = GUICtrlCreateLabel("XPos", 95, 16, 36, 20, $SS_RIGHT)
Global $lblYPos = GUICtrlCreateLabel("YPos:", 7, 34, 40, 20, $SS_RIGHT)
Global $YPos = GUICtrlCreateLabel("YPos", 95, 34, 37, 20, $SS_RIGHT)
Global $lblWinTitle = GUICtrlCreateLabel("Window Title:", 7, 61, 84, 20, $SS_RIGHT)
Global $WinTitle = GUICtrlCreateLabel("WinTitle", 95, 61, 250, 20)
Global $lblHandle = GUICtrlCreateLabel("Handle:", 7, 78, 51, 20, $SS_RIGHT)
Global $WinHandle = GUICtrlCreateLabel("Win Handle", 95, 78, 100, 20)
Global $lblCtrlID = GUICtrlCreateLabel("Control ID:", 7, 104, 65, 20, $SS_RIGHT)
Global $ControlID = GUICtrlCreateLabel("ControlID", 95, 104, 100, 20)
Global $lblCtrlText = GUICtrlCreateLabel("Control Text:", 7, 125, 78, 20, $SS_RIGHT)
Global $ControlText = GUICtrlCreateLabel("Control Text", 95, 125, 120, 20)
Global $lblCtrlPos = GUICtrlCreateLabel("Control Pos:", 7, 144, 76, 20, $SS_RIGHT)
Global $ControlPos = GUICtrlCreateLabel("Control Pos", 95, 144, 73, 20)
Global $btnExit = GUICtrlCreateButton("Exit", 8, 192, 75, 25)
Global $sKey1 = GUICtrlCreateDummy()
; Set GUIAccelerators for the button controlID Ctrl + [F3]
Global $aAccelKeys[1][2] = [["^{F3}", $sKey1]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    If $nMsg <> 0 Then
        ConsoleWrite("GUIGetMsg = " & $nMsg & @CRLF)
        ConsoleWrite("$sKey1 = " & $sKey1 & @CRLF)
    EndIf

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            If $nMsg <> 0 Then
                ConsoleWrite("Event Close = " & $nMsg & @CRLF)
            EndIf
            Exit

        Case $btnExit
            If $nMsg <> 0 Then
                ConsoleWrite("Terminate = " & $nMsg & @CRLF)
            EndIf
            Terminate()

        Case $sKey1
            If $nMsg <> 0 Then
                ConsoleWrite("Report = " & $nMsg & @CRLF)
            EndIf
            $iFile = FileOpen($sFileLogName, 1)
            If $iFile = -1 Then
                MsgBox(0, "Error", "Unable to Open WinfoFile")
            EndIf
            $sWinTitle = WinGetTitle("", "")
            $sWinText = WinGetText($sWinTitle)
            $sWinHnd = WinGetHandle($sWinTitle)
            $sWinCtrlRef = ControlGetFocus($sWinHnd)
            $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef)
            $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef)
            ControlFocus($sWinHnd, "", $sWinCtrlRef)
            $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef)
            $mPos = MouseGetPos()
            If IsString($sWinText) Then
                GUICtrlSetData($WinTitle, $sWinTitle)
            Else
                GUICtrlSetData($WinTitle, "")
            EndIf
            If IsHWnd($sWinHnd) Then
                GUICtrlSetData($WinHandle, $sWinHnd)
            Else
                GUICtrlSetData($WinHandle, "")
            EndIf
            GUICtrlSetData($ControlID, $sWinCtrlRef)
            GUICtrlSetData($ControlText, $sWinCtrlText)
            If IsArray($aPos) Then
                GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1])
                $sControlPos = $aPos[0] & "," & $aPos[1]
            Else
                GUICtrlSetData($ControlPos, "")
                $sControlPos = ""
            EndIf
            If IsArray($mPos) Then
                GUICtrlSetData($XPos, $mPos[0])
                GUICtrlSetData($YPos, $mPos[1])
                $sMousePos = $mPos[0] & "," & $mPos[1]
            Else
                GUICtrlSetData($XPos, "")
                GUICtrlSetData($YPos, "")
                $sMousePos = ""
            EndIf
            $sReport = $sReport & "Window Title     : " & $sWinTitle & @CRLF
            $sReport = $sReport & "Window Text      : " & $sWinText & @CRLF
            $sReport = $sReport & "Window Handle    : " & $sWinHnd & @CRLF
            $sReport = $sReport & "Control Refer    : " & $sWinCtrlRef & @CRLF
            $sReport = $sReport & "Control Text     : " & $sWinCtrlText & @CRLF
            $sReport = $sReport & "Control Handle   : " & $sWinCtrlHnd & @CRLF
            $sReport = $sReport & "Control Position : " & $sControlPos & @CRLF
            $sReport = $sReport & "Mouse Position   : " & $sMousePos & @CRLF
            If $Debug = 1 Then
                ConsoleWrite($sReport & @CRLF)
            EndIf
            FileWriteLine($iFile, "=====================================================")
            FileWriteLine($iFile, $sReport)
            FileWriteLine($iFile, "=====================================================")
            FileClose($iFile)
            If @error = -1 Then
                MsgBox(0, "Error", "Failed")
            Else
                MsgBox(0, "Report", "Report Completed")
            EndIf
    EndSwitch
    $sWinTitle = WinGetTitle("", "")
    $sWinText = WinGetText($sWinTitle)
    $sWinHnd = WinGetHandle($sWinTitle)
    $sWinCtrlRef = ControlGetFocus($sWinHnd)
    $sWinCtrlText = ControlGetText($sWinHnd, "", $sWinCtrlRef)
    $sWinCtrlHnd = ControlGetHandle($sWinHnd, "", $sWinCtrlRef)
    ControlFocus($sWinHnd, "", $sWinCtrlRef)
    $aPos = ControlGetPos($sWinCtrlHnd, "", $sWinCtrlRef)
    $mPos = MouseGetPos()
    If IsString($sWinText) Then
        GUICtrlSetData($WinTitle, $sWinTitle)
    Else
        GUICtrlSetData($WinTitle, "")
    EndIf
    If IsHWnd($sWinHnd) Then
        GUICtrlSetData($WinHandle, $sWinHnd)
    Else
        GUICtrlSetData($WinHandle, "")
    EndIf
    GUICtrlSetData($ControlID, $sWinCtrlRef)
    GUICtrlSetData($ControlText, $sWinCtrlText)
    If IsArray($aPos) Then
        GUICtrlSetData($ControlPos, $aPos[0] & "," & $aPos[1])
        $sControlPos = $aPos[0] & "," & $aPos[1]
    Else
        GUICtrlSetData($ControlPos, "")
        $sControlPos = ""
    EndIf
    If IsArray($mPos) Then
        GUICtrlSetData($XPos, $mPos[0])
        GUICtrlSetData($YPos, $mPos[1])
        $sMousePos = $mPos[0] & "," & $mPos[1]
    Else
        GUICtrlSetData($XPos, "")
        GUICtrlSetData($YPos, "")
        $sMousePos = ""
    EndIf

    ;Sleep(500)
WEnd


Func WriteLogFile()
    Local $iFile
    Local $sFileLogName
    Local $sReport

    $sFileLogName = @WorkingDir & "\WinfoFile" & @YDAY & ".log"
    $iFile = FileOpen($sFileLogName, 1)
    If $iFile = -1 Then
        MsgBox(0, "Error", "Unable to Open WinfoFile")
        Return -1
    EndIf
    $sReport = $sReport & "Window Title     : " & $sWinTitle & @CRLF
    $sReport = $sReport & "Window Text      : " & $sWinText & @CRLF
    $sReport = $sReport & "Window Handle    : " & $sWinHnd & @CRLF
    $sReport = $sReport & "Control Refer    : " & $sWinCtrlRef & @CRLF
    $sReport = $sReport & "Control Text     : " & $sWinCtrlText & @CRLF
    $sReport = $sReport & "Control Handle   : " & $sWinCtrlHnd & @CRLF
    $sReport = $sReport & "Control Position : " & $aPos[0] & "," & $aPos[1] & @CRLF
    $sReport = $sReport & "Mouse Position   : " & $mPos[0] & "," & $mPos[1] & @CRLF
    FileWriteLine($iFile, "=====================================================")
    FileWriteLine($iFile, $sReport)
    FileWriteLine($iFile, "=====================================================")
    FileClose($iFile)
    MsgBox(0, "Report", "Report Completed")
    Return
EndFunc   ;==>WriteLogFile

;======================================================================================
; Function: Terminate Hot Key = Alt+Esc
;======================================================================================
Func Terminate() ; Hot Key = Alt+Esc
    GUIDelete($Coordinates)
    Exit 0
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites

OGW,

When I run your code I get a file containing this

=====================================================
Window Title     : Coordinates
Window Text      : XPos:
849
YPos:
629
Window Title:
Coordinates
Handle:
0x000000000004024E
Control ID:
Button1
Control Text:
Exit
Control Pos:

Exit

Window Handle    : 0x000000000004024E
Control Refer    : Button1
Control Text     : Exit
Control Handle   : 0x00000000000501F8
Control Position : 
Mouse Position   : 849,629
=====================================================

Check where your working dir is.

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
22 hours ago, OldGuyWalking said:

I discovered GUIAccelerators but I'm stuck on what triggers the accelerator key

in the example ( https://www.autoitscript.com/autoit3/docs/functions/GUISetAccelerators.htm ) they use buttons.
The way I make my buttons is:

Local $sKey1 = GUICtrlCreateButton("Ctrl F3", 0, 0, 1, 1)
GUICtrlSetState($sKey1,$GUI_HIDE)

Hope this helps :)

Share this post


Link to post
Share on other sites

Kylomas,

I changed @workingdir to @scriptdir (which is what it should have been in the first place.)  But still not triggering or creating a file. Weird that it would work on your computer and not on mine. 

Thank you for testing it.

Argumentum,

Thanks. Good idea. I've done the same thing in VB and VBA when I needed fields in a form to hold values but didn't need the fields to be visible.

Bill

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

    • Valnurat
      By Valnurat
      How can I get combobox value by using  the ENTER key?
    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • Valnurat
      By Valnurat
      I have a ComboBox and I want, when I start writting in it, that it will show me what is the first in the list.
      Like, is I start writting:
      "pe" it  should show me "peter" if that is the first in the list.
      How can I do that?
       
      While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then For $i = 0 To UBound($aComputerOwner) - 1 GUICtrlCreateListViewItem($aComputerOwner[$i], $idMylist) Next Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd  
    • Valnurat
      By Valnurat
      Hi.
      I'm trying to add an array to my gui listview, but it fails with
      "C:\Program Files (x86)\AutoIt3\Include\GuiListView.au3" (473) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: DllStructSetData($tBuffer, "Text", $aItems[$iI][0]) DllStructSetData($tBuffer, "Text", ^ ERROR My code is:
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #Include <AD.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $aResult[0][2] Local $aNames[4] = ["DKSO","DKKO","SELU","SEES"] Local Const $iWidth = 300, $iHeight = 250, $iW = 85, $iH = 25 Local $hGUI = GUICreate("Find Computer Owner", $iWidth, $iHeight) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("", 2, 2, 296, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT)) ;$WS_VSCROLL Local $idMylist = GUICtrlCreateListView("", 2, 114, 296, 100) Local $idClos = GUICtrlCreateButton("Close", ($iWidth - $iW) / 2, ($iHeight - $iH) - 7 , $iW, $iH) _AD_Open() Local $sFill = "" For $i = 0 to UBound($aNames) -1 Local $aUserInfo = _AD_GetObjectsInOU("OU=Al,DC=ad,DC=al,DC=org","(&(objectCategory=Person)(objectclass=user)(sAMAccountName=" & $aNames[$i] & "*))","","distinguishedName,cn") if @error Then MsgBox(0,@error,@extended) Exit EndIf For $x = $aUserInfo[0][0] To 1 Step -1 If $aUserInfo[$x][0] = "" Or StringInStr($aUserInfo[$x][0], "Resources") > 0 Or StringInStr($aUserInfo[$x][0], "Leavers") > 0 Or StringInStr($aUserInfo[$x][0], "Administration") > 0 Then _ArrayDelete($aUserInfo, $x) EndIf Next _ArrayConcatenate($aResult, $aUserInfo, 1) Next for $i = 0 To UBound($aResult) -1 If $aResult[$i][0] <> "" Then $sFill &= $aResult[$i][1] & "|" EndIf Next _ArrayDisplay($aResult, 'AD ' & UBound($aResult)) $sFill = StringTrimRight($sFill, 1) _GUICtrlComboBox_BeginUpdate($idComboBox) GUICtrlSetData($idComboBox, $sFill, "") _GUICtrlComboBox_EndUpdate($idComboBox) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlListView_AddColumn($idMylist, "Computername", 296) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _ArrayDisplay($aComputerOwner) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then MsgBox(0,"Test",$sComboRead) _GUICtrlListView_AddArray($idMylist, $aComputerOwner) ; <---- it fails Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd _AD_Close() ; Delete the previous GUI and all controls. GUIDelete($hGUI) Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $idMylist If Not IsHWnd($idMylist) Then $hWndListView = GUICtrlGetHandle($idMylist) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Do I do it wrong?
       
      Thank you in advanced.
    • Trisha
      By Trisha
      I tried (using AutoIt) to automate a scenario where i  have to open IE with specific URL on my extranet(Xen Desktop or Citrix ) ,from there i need to download  file and then through WinSCP; I  have to move that file to another location that can be access from my Local system using VMWare.
      I did as far as the above step. Now i want to navigate from my extranet to my local desktop system. But i am not able to move  from there.Mouse click is also not working.Please find the below screenshot highlighted in YELLOW.