Jump to content
OldGuyWalking

Dummy Control Not Triggering

Recommended Posts

OldGuyWalking

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
kylomas

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
argumentum
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
OldGuyWalking

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

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • VollachR
      By VollachR
      Hi,
      I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.
      I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.
      What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.
      It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.
      Here are the relevant part of my script:
      The Custom Verification Arrays:
      ;Creating Arrays for INI Verification Global $aSettingsVerify[7] $aSettingsVerify[1] = "Conversion" $aSettingsVerify[2] = "AIO" $aSettingsVerify[3] = "Data" $aSettingsVerify[4] = "Redist" $aSettingsVerify[5] = "Split" $aSettingsVerify[6] = "Autorun" Global $aDataVerify[6] $aDataVerify[1] = "Compression" $aDataVerify[2] = "Exclude" $aDataVerify[3] = "LangExclude" $aDataVerify[4] = "PreCommands" $aDataVerify[5] = "PostCommands" The IniReadSectionNames verification part:
      Case $OK If StringInStr($ActiveConfig, "Settings.ini") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) SettingsGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf If StringInStr($ActiveConfig, "Data") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) DataGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)
      ;Compares Imported INI file with the Verification array Func _ArrayCompare(ByRef $a1, ByRef $a2) Local $nOldSize = UBound($a2) Local $a3[$nOldSize], $nNewSize = $nOldSize For $i = 0 To UBound($a1) - 1 For $j = 0 To $nOldSize - 1 If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then $a3[$j] = 1 $nNewSize -= 1 EndIf Next Next Local $a4[$nNewSize], $j = 0 For $i = 0 To $nOldSize - 1 If Not $a3[$i] Then $a4[$j] = $a2[$i] $j += 1 EndIf Next Return $a4 EndFunc ;==>_ArrayCompare  
      Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?
      Thanks
    • Valnurat
      By Valnurat
      Can you explain why my mouseclick don't work in my shockwave fullscreen.
       
      I know my syntax is ok, because it moves to coordinates, but this will only press 1 time, even that I want to press 5 times.
      How can that be?
    • nacerbaaziz
      By nacerbaaziz

      Hello
      I have a question please
      How to show Islamic date in Autoit
      I mean
      for example
      Ramadan month
      And moharam month ... etc
      I hope my question is clear for you
      Thanks in advance
×