caramen

[Solved]Auto text

21 posts in this topic

#1 ·  Posted (edited)

Hello guys. 

I totaly reworked a script to get less problem(Melba23) and i used a topic to copy an existing script and modified it. 

Since my last post it was bad evaluated as a spam bot but by my fault since i have not explained the purpose of it corectly. (Yes i got ugly english)

 

Then FIRST OF ALL the purpose of this script is to allow a call center to complet multiple fields in internet explorer and optionnaly; i am gonna see that after the principal code to configure multiple email that can be send. I know there is some UDF for outlook etc... but i want a single script to do all. this is the way i want to do that. 

 

Ok this is my complete code for the moment. 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>


$dll = DllOpen("user32.dll")

Global    $EnvoyerMess1Sub1
Global    $EnvoyerMess2Sub1
Global    $EnvoyerMess3Sub1
Global    $EnvoyerMess4Sub1
Global    $EnvoyerMess5Sub1

Global    $EnvoyerMess1Sub2
Global    $EnvoyerMess2Sub2
Global    $EnvoyerMess3Sub2
Global    $EnvoyerMess4Sub2
Global    $EnvoyerMess5Sub2

Global    $EnvoyerMess1Sub3
Global    $EnvoyerMess2Sub3
Global    $EnvoyerMess3Sub3
Global    $EnvoyerMess4Sub3
Global    $EnvoyerMess5Sub3

Global    $EnvoyerMess1Sub4
Global    $EnvoyerMess2Sub4
Global    $EnvoyerMess3Sub4
Global    $EnvoyerMess4Sub4
Global    $EnvoyerMess5Sub4

Global Const $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)

$Valeur1 = IniRead ($SettingsFile, 'NomMenu', 'Menu1', "ERROR")
$Valeur2 = IniRead ($SettingsFile, 'NomMenu', 'Menu2', "ERROR")
$Valeur3 = IniRead ($SettingsFile, 'NomMenu', 'Menu3', "ERROR")
$Valeur4 = IniRead ($SettingsFile, 'NomMenu', 'Menu4', "ERROR")

$Valeur11 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu1.1', "ERROR")
$Valeur12 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu1.2', "ERROR")
$Valeur13 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu1.3', "ERROR")
$Valeur14 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu1.4', "ERROR")
$Valeur15 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu1.5', "ERROR")

$Valeur21 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu2.1', "ERROR")
$Valeur22 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu2.2', "ERROR")
$Valeur23 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu2.3', "ERROR")
$Valeur24 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu2.4', "ERROR")
$Valeur25 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu2.5', "ERROR")

$Valeur31 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu3.1', "ERROR")
$Valeur32 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu3.2', "ERROR")
$Valeur33 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu3.3', "ERROR")
$Valeur34 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu3.4', "ERROR")
$Valeur35 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu3.5', "ERROR")

$Valeur41 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu4.1', "ERROR")
$Valeur42 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu4.2', "ERROR")
$Valeur43 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu4.3', "ERROR")
$Valeur44 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu4.4', "ERROR")
$Valeur45 = IniRead ($SettingsFile, 'NomMenu', 'SousMenu4.5', "ERROR")

$Message11 = IniRead ($SettingsFile, 'Messages', 'Message11', "ERROR")
$Message12 = IniRead ($SettingsFile, 'Messages', 'Message11', "ERROR")
$Message13 = IniRead ($SettingsFile, 'Messages', 'Message11', "ERROR")
$Message14 = IniRead ($SettingsFile, 'Messages', 'Message11', "ERROR")
$Message15 = IniRead ($SettingsFile, 'Messages', 'Message11', "ERROR")

$Message21 = IniRead ($SettingsFile, 'Messages', 'Message21', "ERROR")
$Message22 = IniRead ($SettingsFile, 'Messages', 'Message22', "ERROR")
$Message23 = IniRead ($SettingsFile, 'Messages', 'Message23', "ERROR")
$Message24 = IniRead ($SettingsFile, 'Messages', 'Message24', "ERROR")
$Message25 = IniRead ($SettingsFile, 'Messages', 'Message25', "ERROR")

$Message31 = IniRead ($SettingsFile, 'Messages', 'Message31', "ERROR")
$Message32 = IniRead ($SettingsFile, 'Messages', 'Message32', "ERROR")
$Message33 = IniRead ($SettingsFile, 'Messages', 'Message33', "ERROR")
$Message34 = IniRead ($SettingsFile, 'Messages', 'Message34', "ERROR")
$Message35 = IniRead ($SettingsFile, 'Messages', 'Message35', "ERROR")

$Message41 = IniRead ($SettingsFile, 'Messages', 'Message41', "ERROR")
$Message42 = IniRead ($SettingsFile, 'Messages', 'Message42', "ERROR")
$Message43 = IniRead ($SettingsFile, 'Messages', 'Message43', "ERROR")
$Message44 = IniRead ($SettingsFile, 'Messages', 'Message44', "ERROR")
$Message45 = IniRead ($SettingsFile, 'Messages', 'Message45', "ERROR")

BuildHiddenGUI()

While 1
    Sleep ( 10 )
    If _IsPressed("04", $dll) Then CallCustomContextMenu()
    $msg = GUIGetMsg()
    Switch $msg

;~ =====================================================

        Case $EnvoyerMess1Sub1
;~         MouseClick("left")

           Send(""&$Message11)

        Case $EnvoyerMess2Sub1
           Send(""&$Message12)

        Case $EnvoyerMess3Sub1
           Send(""&$Message13)

        Case $EnvoyerMess4Sub1
           Send(""&$Message14)

        Case $EnvoyerMess5Sub1
           Send(""&$Message15)

;~ ======================================================

        Case $EnvoyerMess1Sub2

        Case $EnvoyerMess2Sub2

        Case $EnvoyerMess3Sub2

        Case $EnvoyerMess4Sub2

        Case $EnvoyerMess5Sub2

;~ ======================================================

        Case $EnvoyerMess1Sub3

        Case $EnvoyerMess2Sub3

        Case $EnvoyerMess3Sub3

        Case $EnvoyerMess4Sub3

        Case $EnvoyerMess5Sub3


;~ =======================================================

        Case $EnvoyerMess1Sub4

        Case $EnvoyerMess2Sub4

        Case $EnvoyerMess3Sub4

        Case $EnvoyerMess4Sub4

        Case $EnvoyerMess5Sub4

;~ ======================================================

        Case $ConfigITEM

    EndSwitch

WEnd
DllClose($dll)

Func BuildHiddenGUI()
    Global $Contextmenu, $msg, $GUI, $aTSR
    Global $SubMenu1, $folderitem, $programitem, $fileitem, $ConfigITEM, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    $aTSR = _GetTotalScreenResolution()

    $GUI = GuiCreate("GUI Context Menu",1,1, $aTSR[0], 1,BitOR($WS_POPUP,$WS_BORDER),BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
    WinSetTrans( $GUI, '', 1)

    GUISetState()

    $Contextmenu = GUICtrlCreateContextMenu()
    $SubMenu1 = GUICtrlCreateMenu(""&$Valeur1, $Contextmenu)
      $EnvoyerMess1Sub1 = GUICtrlCreateMenuItem(""&$Valeur11, $SubMenu1)
      $EnvoyerMess2Sub1 = GUICtrlCreateMenuItem(""&$Valeur12, $SubMenu1)
      $EnvoyerMess3Sub1 = GUICtrlCreateMenuItem(""&$Valeur13, $SubMenu1)
      $EnvoyerMess4Sub1 = GUICtrlCreateMenuItem(""&$Valeur14, $SubMenu1)
      $EnvoyerMess5Sub1 = GUICtrlCreateMenuItem(""&$Valeur15, $SubMenu1)
    $SubMenu2 = GUICtrlCreateMenu(""&$Valeur2, $Contextmenu)
      $EnvoyerMess1Sub2 = GUICtrlCreateMenuItem(""&$Valeur21, $SubMenu2)
      $EnvoyerMess2Sub2 = GUICtrlCreateMenuItem(""&$Valeur22, $SubMenu2)
      $EnvoyerMess3Sub2 = GUICtrlCreateMenuItem(""&$Valeur23, $SubMenu2)
      $EnvoyerMess4Sub2 = GUICtrlCreateMenuItem(""&$Valeur24, $SubMenu2)
      $EnvoyerMess5Sub2 = GUICtrlCreateMenuItem(""&$Valeur25, $SubMenu2)
    $SubMenu3 = GUICtrlCreateMenu(""&$Valeur3, $Contextmenu)
      $EnvoyerMess1Sub3 = GUICtrlCreateMenuItem(""&$Valeur31, $SubMenu3)
      $EnvoyerMess2Sub3 = GUICtrlCreateMenuItem(""&$Valeur32, $SubMenu3)
      $EnvoyerMess3Sub3 = GUICtrlCreateMenuItem(""&$Valeur33, $SubMenu3)
      $EnvoyerMess4Sub3 = GUICtrlCreateMenuItem(""&$Valeur34, $SubMenu3)
      $EnvoyerMess5Sub3 = GUICtrlCreateMenuItem(""&$Valeur35, $SubMenu3)
    $SubMenu4 = GUICtrlCreateMenu(""&$Valeur4, $Contextmenu)
      $EnvoyerMess1Sub4 = GUICtrlCreateMenuItem(""&$Valeur41, $SubMenu4)
      $EnvoyerMess2Sub4 = GUICtrlCreateMenuItem(""&$Valeur42, $SubMenu4)
      $EnvoyerMess3Sub4 = GUICtrlCreateMenuItem(""&$Valeur43, $SubMenu4)
      $EnvoyerMess4Sub4 = GUICtrlCreateMenuItem(""&$Valeur44, $SubMenu4)
      $EnvoyerMess5Sub4 = GUICtrlCreateMenuItem(""&$Valeur45, $SubMenu4)

    GUICtrlCreateMenuItem("", $contextmenu)     ; separator

   $ConfigITEM = GUICtrlCreateMenuItem("Configuration", $contextmenu)
EndFunc

Func CallCustomContextMenu()
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

Func _GetTotalScreenResolution()
    Local $aRet[2], $VirtualDesktopWidth, $VirtualDesktopHeight
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

Func WinGroupActive()
    AutoItSetOption("WinTitleMatchMode", 4)
    If WinActive("classname=ExploreWClass") _
        Or WinActive("classname=CabinetWClass") _
        Or WinActive("classname=#32770") _
        Or WinActive("classname=DV2ControlHost") _
        Or WinActive("classname=MMCMainFrame") _
        Or WinActive("[CLASS:Progman; Title:Program Manager]") Then
        Return True
    Else
        Return False
    EndIf
EndFunc

 

By this way the script is very more clear about the purpose. When i use middle mouse click i got a context menu that apear. Then i can send the preconfigured message in the ini file that will alow me to send particular message without spending much time on it. 

First question : 

When i push middle click on a particular windows how to get back focus on it ??

plz dont make attention on the declared fonction that are unused i am gonna clean that at the end. 

Edited by caramen

Share this post


Link to post
Share on other sites



i thougth about 

$windows =  WinGetTitle("[active]")
            WinActivate (""&$windows)

but where tu put the function WinGetTitle? 

Share this post


Link to post
Share on other sites

solution : 

Func CallCustomContextMenu()
    Global      $windows =  WinGetTitle("[active]")
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

thx.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Script is finish and work well but i got a new improvement but difficult for me again x)

 

Since i use Settings.ini file and i read all values at the start of the script and not in the gui loop

If i change any value in the ini file i need to Quit my script executable and luch it again 

 

Is there a way to close the script and start it again after changing a value automaticaly ? :blink:

Edited by caramen

Share this post


Link to post
Share on other sites

Solution : 

 

Thx x)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It's possible without restarting. Just put all inireads in a func. This func has to be called at script start and on button click "ReRead INI". Therefor this "ReRead INI"-button has to be implementet in you GUI.

Edited by AutoBert

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I thougth about that and tryed with bad logic,

include made me add 3 line of code x) it s better :P 

 

THx

Edited by caramen

Share this post


Link to post
Share on other sites

Now this is my problem :  

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <Restart.au3>


$dll = DllOpen("user32.dll")


Global $fInterrupt = False

Global $cButton = "NO"


Global    $Boucle
Global    $BoucleStop


Global Const $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)


$MessageBoucle = IniRead ($SettingsFile, 'Messages', 'MessageBoucle', "ERROR")

BuildHiddenGUI()

While 1
    Sleep ( 10 )
    If _IsPressed("04", $dll) Then CallCustomContextMenu()
    $msg = GUIGetMsg()
    Switch $msg



        Case $Boucle
           GUICtrlSetData($cButton, "No")
                    _Running()

           WinActivate (""&$windows)
                    Sleep (5000)
           Send(""&$MessageBoucle)
                    Sleep (5000)

        Case $BoucleStop
           GUICtrlSetData($cButton, "Yes")


    EndSwitch

WEnd
DllClose($dll)

Func BuildHiddenGUI()
    Global $Contextmenu, $msg, $GUI, $aTSR
    Global $SubMenu1, $folderitem, $programitem, $fileitem, $ConfigITEM, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    $aTSR = _GetTotalScreenResolution()

    $GUI = GuiCreate("GUI Context Menu",1,1, $aTSR[0], 1,BitOR($WS_POPUP,$WS_BORDER),BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
    WinSetTrans( $GUI, '', 1)

    GUISetState()

    $Contextmenu = GUICtrlCreateContextMenu()


    $Boucle = GUICtrlCreateMenuItem("Boucle", $contextmenu)
    $BoucleStop = GUICtrlCreateMenuItem("Boucle Stop", $contextmenu)

    GUICtrlCreateMenuItem("", $contextmenu)

    $Aide = GUICtrlCreateMenuItem("Aide", $contextmenu)



EndFunc

Func CallCustomContextMenu()
    Global      $windows =  WinGetTitle("[active]")
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

Func _GetTotalScreenResolution()
    Local $aRet[2], $VirtualDesktopWidth, $VirtualDesktopHeight
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

Func WinGroupActive()
    AutoItSetOption("WinTitleMatchMode", 4)
    If WinActive("classname=ExploreWClass") _
        Or WinActive("classname=CabinetWClass") _
        Or WinActive("classname=#32770") _
        Or WinActive("classname=DV2ControlHost") _
        Or WinActive("classname=MMCMainFrame") _
        Or WinActive("[CLASS:Progman; Title:Program Manager]") Then
        Return True
    Else
        Return False
    EndIf
 EndFunc

 Func _Running()

    ConsoleWrite("Running"  & @CRLF) ; Now we are here we can no longer read the main loop

    ; Here we run our loop checking every second if the flag has been set in the handler
    $nBegin = TimerInit()
    Do
        Sleep(1000)

        ; Here we look for the flag set in the handler
        If $fInterrupt = True Then
            ConsoleWrite("Interrupted" & @CRLF)
            ; Reset the flag
            $fInterrupt = False
            ; And return early
            Return
        EndIf
        ConsoleWrite("Still running!" & @CRLF)

    Until TimerDiff($nBegin) > 50000

    ; Now the loop has finished naturally

EndFunc   ;==>_Running

 Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    ; The button was pressed
    If BitAND($wParam, 0x0000FFFF) = $cButton Then
        Switch GUICtrlRead($cButton)
            ; We only want to react if the function is already running
            Case "No"
                ; Set the flag
                $fInterrupt = True
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_COMMAND

(i made reproducer to make the script shorter) 

I added these case :

Case $Boucle
           GUICtrlSetData($cButton, "No")
                    _Running()

           WinActivate (""&$windows)
                    Sleep (5000)
           Send(""&$MessageBoucle)
                    Sleep (5000)

        Case $BoucleStop
           GUICtrlSetData($cButton, "Yes")

 

i whould like to make the loop and exit loop after Case

$BoucleStop

I tryed the help given in that post : 

 

but cant get it working. 

Share this post


Link to post
Share on other sites

@caramen: please don't pm me, after the pm i remember this thread is only pseudo for 2 locked threads.

Quote

caramen,

When you asked via PM if you could post a thread about interrupting a loop I did not expect you to repost essentially the same code as in the thread I locked yesterday.

and in the other way, why needing help:

 

1 hour ago, caramen said:

include made me add 3 line of code x) it s better :P 

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I pm you to get faster answer* 

I did what melba requested (rework the code) (and explain the purpose ) (like i explained you in the PM :/ ) 

Edited by caramen

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

but your real attempt is still against forumrules, so please don't pm me. The way to solve is already showed:

1 hour ago, AutoBert said:

It's possible without restarting. Just put all inireads in a func. This func has to be called at script start and on button click "ReRead INI". Therefor this "ReRead INI"-button has to be implementet in you GUI.

but you find a better solution:

1 hour ago, caramen said:

I thougth about that and tryed with bad logic,

include made me add 3 line of code x) it s better :P 

 

THx

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I am sorry man. You are mistaking about the question. 

 

The first question is answered : how to restart the script ? 

 

The second question is an other probleme : How to stop the loop during the case execution ?

Or may the restart script is a solution ? (but i cant get the context menu again while i am in the loop)

 

Edited by caramen

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

And trust me i canT afford an other warning so be sure i took attention about not breaking any rule .... :sweating: 

 

Or maybe it s me mistaking ? In this case i am gonna retract any question and stop posting. 

Edited by caramen

Share this post


Link to post
Share on other sites
3 minutes ago, caramen said:

And trust me i canT afford an other warning so be sure i took attention about not breaking any rule

Don't be too sure that isn't coming ... you are in the queue for review and zero credit left.. verdict will be there soon so better lay very low till then.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

When i say i cant afford i main : i must not have an other one. did i spelled whrong ?

Share this post


Link to post
Share on other sites

caramen,

This time you have explained yourself clearly in the OP and not just spoken of a "spambot" (which is why the thread was locked last time), so we are going to leave the thread open.

However, the Forum rules clearly prohibit PMing others for help, so consider yourself suitably admonished for doing so - please do not make a habit of it in future.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I am on the good way xD. Thanks melba i thougth i was mistaking again. Jos made me afraid a lot :sweating:.

 

So i repost a reworked Reproducer to try to get the while working. Can someone help me ?

 

I am trying to push middle click:

-Start loop by clicking : Boucle

Re push middle click 

-Stop loop if i click : Boucle Stop

This is for send msg on monitored server. 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <Restart.au3>


$dll = DllOpen("user32.dll")


Global $fInterrupt = False

Global $Flag = "Yes"


Global    $Boucle
Global    $BoucleStop


Global Const $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)
IniWrite ($SettingsFile, 'Messages', 'MessageBoucle','Message test')

$MessageBoucle = IniRead ($SettingsFile, 'Messages', 'MessageBoucle', "ERROR")

BuildHiddenGUI()

While 1
    Sleep ( 10 )
    If _IsPressed("04", $dll) Then CallCustomContextMenu()
    $msg = GUIGetMsg()
    Switch $msg



        Case $Boucle
           $Flag = "Yes"
                    _Running()

           WinActivate (""&$windows)
           Send(""&$MessageBoucle)
                    Sleep (5000)
        Case $BoucleStop
           $Flag= "Yes"


    EndSwitch

WEnd

DllClose($dll)

;~ =========================================GUI================================================


Func BuildHiddenGUI()
    Global $Contextmenu, $msg, $GUI, $aTSR
    Global $SubMenu1, $folderitem, $programitem, $fileitem, $ConfigITEM, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    $aTSR = _GetTotalScreenResolution()

    $GUI = GuiCreate("GUI Context Menu",1,1, $aTSR[0], 1,BitOR($WS_POPUP,$WS_BORDER),BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
    WinSetTrans( $GUI, '', 1)

    GUISetState()

    $Contextmenu = GUICtrlCreateContextMenu()


    $Boucle = GUICtrlCreateMenuItem("Boucle", $contextmenu)
    $BoucleStop = GUICtrlCreateMenuItem("Boucle Stop", $contextmenu)

    GUICtrlCreateMenuItem("", $contextmenu)

    $Aide = GUICtrlCreateMenuItem("Aide", $contextmenu)



EndFunc



Func CallCustomContextMenu()
    Global      $windows =  WinGetTitle("[active]")
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

Func _GetTotalScreenResolution()
    Local $aRet[2], $VirtualDesktopWidth, $VirtualDesktopHeight
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

;~ =========================================================================================


;~ ========================================While attemp=================================================


 Func _Running()

    ConsoleWrite("Running"  & @CRLF) ; Now we are here we can no longer read the main loop

    ; Here we run our loop checking every second if the flag has been set in the handler
    $nBegin = TimerInit()
    Do
        Sleep(1000)

        ; Here we look for the flag set in the handler
        If $fInterrupt = True Then
            ConsoleWrite("Interrupted" & @CRLF)
            ; Reset the flag
            $fInterrupt = False
            ; And return early
            Return
        EndIf
        ConsoleWrite("Still running!" & @CRLF)

    Until TimerDiff($nBegin) > 50000

    ; Now the loop has finished naturally

EndFunc   ;==>_Running

 Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

    ; The button was pressed
    If BitAND($wParam, 0x0000FFFF) = $Flag Then
        Switch $cButton
            ; We only want to react if the function is already running
            Case $Msg
                ; Set the flag
                $fInterrupt = True
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_COMMAND

;~ =====================================================================================================

 

Edited by caramen

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

@Melba23 can you explain me how to do the trick you explained me but with that kinda script ?

 

I have to admite i cant realy understand that trick i dont realy want a posted script made by you but i whould prefer understand the trick to make my own script. 

 

I can read the tutorial about flags and try lot of things to introduce exemples.but  i am not getting anything working. what i am missing ?

 

Edited by caramen

Share this post


Link to post
Share on other sites

I am still working on this and trying. But failing :/ 

Reworked reproducer : 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <Restart.au3>

Opt("GUIOnEventMode", 0)

$dll = DllOpen("user32.dll")


Global $fInterrupt = False

Global $Flag = "Yes"


Global    $Boucle
Global    $Reload
Global    $BoucleStop


Global Const $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)
IniWrite ($SettingsFile, 'Messages', 'MessageBoucle','Message test')

$MessageBoucle = IniRead ($SettingsFile, 'Messages', 'MessageBoucle', "ERROR")

BuildHiddenGUI()

While 1
;~    Global        $windows =  WinGetTitle("[active]")
    Sleep ( 10 )
    If _IsPressed("04", $dll) Then CallCustomContextMenu()
    $msg = GUIGetMsg()
    Switch $msg



        Case $Boucle
           WinActivate (""&$windows)
           _Running()

        Case $BoucleStop

           WinActivate (""&$windows)

        Case $Reload
             _ScriptRestart()

    EndSwitch

WEnd

DllClose($dll)

;~ =========================================GUI================================================


Func BuildHiddenGUI()
    Global $Contextmenu, $msg, $GUI, $aTSR
    Global $SubMenu1, $folderitem, $programitem, $fileitem, $ConfigITEM, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    $aTSR = _GetTotalScreenResolution()

    $GUI = GuiCreate("GUI Context Menu",1,1, $aTSR[0], 1,BitOR($WS_POPUP,$WS_BORDER),BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
    WinSetTrans( $GUI, '', 1)

    GUISetState()

    $Contextmenu = GUICtrlCreateContextMenu()


    $Boucle = GUICtrlCreateMenuItem("Boucle", $contextmenu)
     GUICtrlSetOnEvent($Boucle, "_Running")
    $BoucleStop = GUICtrlCreateMenuItem("Boucle Stop", $contextmenu)
     GUICtrlSetOnEvent($BoucleStop, "")
    $Reload = GUICtrlCreateMenuItem("Reload", $contextmenu)
     GUICtrlSetOnEvent($Reload, "_ScriptRestart")


    GUICtrlCreateMenuItem("", $contextmenu)

    $Aide = GUICtrlCreateMenuItem("Aide", $contextmenu)



EndFunc



Func CallCustomContextMenu()
    Global      $windows =  WinGetTitle("[active]")
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

Func _GetTotalScreenResolution()
    Local $aRet[2], $VirtualDesktopWidth, $VirtualDesktopHeight
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

;~ =========================================================================================


;~ ========================================While attemp=================================================


 Func _Running()

     For $i = 1 To 20
         ConsoleWrite("-Func 1 Running" & @CRLF)
         Sleep(100)
     Next
     ConsoleWrite(">Func 1 Ended" & @CRLF)

EndFunc   ;==>_Running

Some question apear... 

 

Why? 

If i use ("GUIOnEventMode", 1) my function is running but i cant open the GUI context menu anymore. this little script part make me so crazy. guess i am gonna give up :(

 

Share this post


Link to post
Share on other sites

While your sample do "_Running()", the while is on the "Case $Boucle". So "CallCustomContextMenu()" can be done only after _Running() End.

While u do "For $i = 1 To 20 sleep(100)", "_IsPressed" is not fire.

You should look maybe arround AdlibRegister :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
;#Include <Restart.au3>

Opt("GUIOnEventMode", 0)

$dll = DllOpen("user32.dll")


Global $fInterrupt = False

Global $Flag = "Yes"


Global    $Boucle
Global    $Reload
Global    $BoucleStop


Global Const $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)
IniWrite ($SettingsFile, 'Messages', 'MessageBoucle','Message test')

$MessageBoucle = IniRead ($SettingsFile, 'Messages', 'MessageBoucle', "ERROR")

BuildHiddenGUI()

While 1
;~    Global        $windows =  WinGetTitle("[active]")
    Sleep ( 10 )
    If _IsPressed("04", $dll) Then CallCustomContextMenu()
    $msg = GUIGetMsg()
    Switch $msg



        Case $Boucle
           WinActivate (""&$windows)
           ;_Running()
           AdlibRegister("_Running", 100); fire _Running all 100ms

        Case $BoucleStop

           WinActivate (""&$windows)
           AdlibUnRegister("_Running")
           ConsoleWrite(">Func 1 Ended" & @CRLF)

        Case $Reload
             ;_ScriptRestart()

    EndSwitch

WEnd

DllClose($dll)

;~ =========================================GUI================================================


Func BuildHiddenGUI()
    Global $Contextmenu, $msg, $GUI, $aTSR
    Global $SubMenu1, $folderitem, $programitem, $fileitem, $ConfigITEM, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    $aTSR = _GetTotalScreenResolution()

    $GUI = GuiCreate("GUI Context Menu",1,1, $aTSR[0], 1,BitOR($WS_POPUP,$WS_BORDER),BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
    WinSetTrans( $GUI, '', 1)

    GUISetState()

    $Contextmenu = GUICtrlCreateContextMenu()


    $Boucle = GUICtrlCreateMenuItem("Boucle", $contextmenu)
     GUICtrlSetOnEvent($Boucle, "_Running")
    $BoucleStop = GUICtrlCreateMenuItem("Boucle Stop", $contextmenu)
     GUICtrlSetOnEvent($BoucleStop, "")
    $Reload = GUICtrlCreateMenuItem("Reload", $contextmenu)
     ;GUICtrlSetOnEvent($Reload, "_ScriptRestart")


    GUICtrlCreateMenuItem("", $contextmenu)

    $Aide = GUICtrlCreateMenuItem("Aide", $contextmenu)



EndFunc



Func CallCustomContextMenu()
    Global      $windows =  WinGetTitle("[active]")
    Local $contextmenu, $msg
    Global $newsubmenu, $folderitem, $programitem, $fileitem, $otheritem
    Global $folderitem1, $folderitem2, $programitem1, $programitem2
    Local $pos
    Global $GUI, $aTSR
    WinActivate ($GUI)
    ControlClick ( $GUI, "", "", "right", 1, $aTSR[0], 1)
EndFunc

Func _GetTotalScreenResolution()
    Local $aRet[2], $VirtualDesktopWidth, $VirtualDesktopHeight
    Global Const $SM_VIRTUALWIDTH = 78
    Global Const $SM_VIRTUALHEIGHT = 79
    $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
    $aRet[0] = $VirtualDesktopWidth[0]
    $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
    $aRet[1] = $VirtualDesktopHeight[0]
    Return $aRet
EndFunc

;~ =========================================================================================


;~ ========================================While attemp=================================================


 Func _Running()

     ;For $i = 1 To 20
         ConsoleWrite("-Func 1 Running" & @CRLF)
         ;Sleep(100)
     ;Next
     ;ConsoleWrite(">Func 1 Ended" & @CRLF)

 EndFunc   ;==>_Running

 

1 person likes this

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

    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • thoms
      By thoms
      Hello Forum,
      I'm trying to vertically center text in label controls, but no way. The search on the forum returns no result, or I don't search the right way
      When I insert a button and a label of same size close to each other, the text is centered on the button, but top aligned on the label, or edit. Which doesn't look really aesthetic
      Any idea is welcome
      Thanks in advance,
      Thoms
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I am a totally blind young man
      for easier to read books and articles Among the blind
      i has programmed a tool
      This tool converts text to audio with the possibility to save it into a wav or mp3 file
      It is also compatible with all persons, whether blind or ordinary
      I have completed the work of this tool and want to take your opinion
      i Especially published here for anyone looking about how to convert text to speech, I will put this tool open source for you
      I want to know what your think about it
      and if it need any other additions?
      Note :
      This tool converts texts to audio using sapi 5 voices
      so i was also puted a hot keys to control the tool
      Now I put this project to you for public benefit and I am ready to answer any question.
      Apology :
      I am an Arab youth from Algeria
      I do not mastered English very well
      So I apologize to you if there are written mistakes
      With my greetings and best wishes
      My texts to audio converter.zip
    • FroVN
      By FroVN
      Hi, i want read all text in website doc.google, link : https://docs.google.com/document/d/1ePaOK3w4mOi0fmOF7WQmF5kYvAXQtztVI7018wei_xs/edit (This is all my account , don't remember :v) how i read all text in this web? Tks
    • StMaSi
      By StMaSi
      Two questions...
      When presenting a form containing a richedit control, is there any way to make the displayed text, within said richedit control, non-selectable?
      In addition, is there any way to hide the vertical line cursor, within said richedit control?
      Thanx.