Jump to content

Mouse click to send "Continue, Exit" message


Jadog
 Share

Recommended Posts

I have a script that does quite a lot of work for me, but I would like to see a message prompt to "Continue or Exit" if I click the mouse while the script is running. I would like clicking Exit to close a few programs (e.g Notepad.exe) and then end the script. In other words, if the script needs to be interrupted, then it could "clean up" after itself by closing the programs it had opened. Is that possible?

Link to comment
Share on other sites

  • Moderators

Jadog,

How are you going to distinguish the mouseclick to close your script from any other mouseclick you make when using NotePad, etc? :D

Perhaps clicking on the script tray icon might be more useful. If you think this might be a suitable solution, then here is some code to get you started: :rip:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#Include <GuiToolBar.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

TrayCreateItem("About")
TrayItemSetOnEvent(-1, "On_About")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

TraySetState()

TraySetClick(8)

; Set left click to show the dislog
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Dialog")

; Set tray icon tool tip
$sToolTipText = "My Dialog"
TraySetToolTip($sToolTipText)

Global $iIcon_X, $iIcon_Y

; Find the tray icon
_Locate_Icon()

; Create and hide the GUI
GUICreate("My Dialog", 200, 200, $iIcon_X - 200, $iIcon_Y - 240)
GUISetState(@SW_HIDE)

While 1

    Switch GUIGetMsg()
        ; Pressing either [_] or [X] rehides the GUI
        Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE)
    EndSwitch

WEnd


Func On_Dialog()

    ; Show the GUI
    GUISetState(@SW_SHOW)

EndFunc

Func _Locate_Icon   ()

    ; Find taskbar
    Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "")
    ; Start icon position calculation
    $iIcon_X = $aPos[0]
    $iIcon_Y = $aPos[1]
    ; Get systray handle and position
    Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then Return
    ; Continue icon position calculation
    $iIcon_X += $aPos[0]
    $iIcon_Y += $aPos[1]
    ; Get systray item count
    Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSysTray_ButCount = 0 Then Return
    ; Look for tooltip by finding track title
    For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1
        Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber)
        If StringInStr($sText, $sToolTipText) > 0 Then
            ; Get coords of icon
            $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSysTray_ButtonNumber)
            ; Finalise icon position calculation
            $iIcon_X += $aPos[0]
            $iIcon_Y += $aPos[1]
            ExitLoop
        EndIf
        If $iSysTray_ButtonNumber = $iSysTray_ButCount - 1 Then Return 1
    Next

    Return 0

EndFunc

Func On_About()
    MsgBox(0, "About", "Whatever")
EndFunc

Func On_Exit()
    Exit
EndFunc

Please ask if you have any questions. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I don't have any mouse clicks in my script, but I do see what you mean. The script may take as long as a few hours to execute and it will fail if someone starts trying to use the computer for something else - which is ok, I'd just like it to close the open programs cleanly and exit the script. I know I can use the block input function, but I want the user to be able to take control of the computer if they need it. So prompting with a message from mouse input seemed like the logical way to achieve this.

Link to comment
Share on other sites

  • Moderators

Jadog,

Take a look at MrCreatoR's BlockInputEx UDF. Then you can block nearly all input, but leave a single way for the user to take control if required. :oops:

Any use? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks Melba23! That looks good. I think this is getting me closer. So I think the following could be modified to fit what I'm looking for:

#include <BlockInputEx.au3>
;================== MouseEvents blocking Example ==================
HotKeySet("{ESC}", "_Quit") ;This will trigger an exit
;Here we block *Mouse* input, except the mouse movement and the wheel button scrolling.
_BlockInputEx(2, "{MMOVE}|{MWSCROLL}")
;This is only for testing, so if anything go wrong, the script will exit after 10 seconds.
AdlibRegister("_Quit", 10000)
While 1
Sleep(100)
WEnd
Func _Quit()
Exit
EndFunc

This would still allow the user to move the mouse, but no clicks would be allowed. Is there a way that a message could be displayed in the for ground during the time that my script is running - it could be a message box that displays "Press the Esc key at any time to stop". The problem is that my script uses the winwaitactive/winactivate functions and if another window is in on top then it seems to stop. I'm sorry to be so new at this stuff. Thanks for being so helpful.

Link to comment
Share on other sites

  • Moderators

Jadog,

Thanks for being so helpful

My pleasure! :oops:

How about a tickertape marquee like this: :rip:

#include <Marquee.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Local $File = FileOpen("mess.txt", 0)
Local $label = "Press the Esc key at any time to stop"
Global $aMarquee_Coords[4] = [0, 0, @DesktopWidth, 60]
Global $fMarquee_Pos = "top"

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

Global $hTray_Top_Item = TrayCreateItem("Top")
TrayItemSetOnEvent(-1, "On_Place")
Global $hTray_Bot_Item = TrayCreateItem("Bottom")
TrayItemSetOnEvent(-1, "On_Place")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

TraySetState()

Find_Taskbar($aMarquee_Coords)
If @error Then MsgBox(0, "Error", "Could not find taskbar")

$hGUI = GUICreate("ScrollingMarquee v1.0", $aMarquee_Coords[2], $aMarquee_Coords[3], $aMarquee_Coords[0], $aMarquee_Coords[1], $WS_POPUPWINDOW, $WS_EX_TOPMOST)
AdlibRegister("Refresh", 35000)
_GUICtrlMarquee_SetScroll(0, Default, "left", Default, 120)
_GUICtrlMarquee_SetDisplay(1, 0x000000, 0x99CCFF, 26, "Comic Sans MS")
_GUICtrlMarquee_Create($label, 0, 0, $aMarquee_Coords[2], $aMarquee_Coords[3])

GUISetState()

While 1
    Sleep(10)
WEnd

Func Refresh()
    If WinExists("ScrollingMarquee v1.0") Then
        WinClose("ScrollingMarquee v1.0")
        Run("ScrollingMarquee.exe")
    EndIf
EndFunc   ;==>Refresh

Func On_Exit()
    Exit
EndFunc

Func On_Place()

    If $fMarquee_Pos = "top" Then
        $fMarquee_Pos = "bottom"
    Else
        $fMarquee_Pos = "top"
    EndIf

    Find_Taskbar($aMarquee_Coords)
    WinMove($hGUI, "", $aMarquee_Coords[0], $aMarquee_Coords[1], $aMarquee_Coords[2], $aMarquee_Coords[3])

EndFunc

Func Find_Taskbar(ByRef $aMarquee_Coords)

    ; Find systray and get size
    Local $iPrevMode = AutoItSetOption("WinTitleMatchMode", 4)
    Local $aTray_Pos = WinGetPos("classname=Shell_TrayWnd")
    AutoItSetOption("WinTitleMatchMode", $iPrevMode)

    ; If error in finding systray
    If Not IsArray($aTray_Pos) Then Return SetError(1, 0)

    ; Determine position of taskbar
    If $aTray_Pos[1] > 0 Then
        ; Taskbar at BOTTOM so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - $aTray_Pos[3] - 60
        EndIf
    ElseIf $aTray_Pos[0] > 0 Then
        ; Taskbar at RIGHT so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth - $aTray_Pos[2]
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    ElseIf $aTray_Pos[2] = @DesktopWidth Then
        ; Taskbar at TOP so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = $aTray_Pos[3]
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    ElseIf $aTray_Pos[3] = @DesktopHeight Then
        ; Taskbar at LEFT so coords of the marquee are
        $aMarquee_Coords[0] = $aTray_Pos[2]
        $aMarquee_Coords[2] = @DesktopWidth - $aTray_Pos[2]
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    EndIf

EndFunc

Any use? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

jadog, just a little note of advice you could look into. put a timeout on the "continue, exit" screen. if the user wanted to take control then he or her will hit exit in the allowed time, if it was triggered from something else like a twinkie thrown across the room in rage then it wont be frozen on the screen till you realise what has gone of.

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Link to comment
Share on other sites

  • Moderators

Jadog,

I did something wrong, didn't I?

No, I did! :oops:

I forgot to mention that you need my Marquee UDF. You can find it via the link in my sig - you need to copy the upper code box and save it as Marquee.au3 in the same folder as your script. Sorry! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Wow, I think I may be in over my head here. So how do I combine your script with this?

#include <BlockInputEx.au3>
;================== MouseEvents blocking Example ==================
HotKeySet("{ESC}", "_Quit") ;This will trigger an exit
;Here we block *Mouse* input, except the mouse movement and the wheel button scrolling.
_BlockInputEx(2, "{MMOVE}|{MWSCROLL}")
;This is only for testing, so if anything go wrong, the script will exit after 10 seconds.
AdlibRegister("_Quit", 10000)
While 1
Sleep(100)
WEnd
Func _Quit()
Exit
EndFunc

And then where does my current script need to go in all of this? Sorry to be so dumb...really wish I new more about this stuff.

Link to comment
Share on other sites

  • Moderators

Jadog,

Sorry to be so dumb...really wish I new more about this stuff

No need to apologise - we all started at that point! :oops:

how do I combine your script with this?

Like this - the marquee is all done in the section between the ####### lines (although you do need the 2 functions as well). Your script would fit in where I have indicated <<<<<<<<<<<<<<<<<< :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Marquee.au3>
#include <BlockInputEx.au3>

HotKeySet("{ESC}", "_Quit") ;This will trigger an exit

;####################################################

; Set a few values
Global $sLabel = "Press the Esc key at any time to stop" ; or whatever text you want
Global $fMarquee_Pos = "top"                             ; or you can use "bottom" if you want it there ;)
Global $aMarquee_Coords[4] = [0, 0, @DesktopWidth, 60]

; Determine the coords for the marquee depending on the taskbar position
_Find_Taskbar($aMarquee_Coords)

_Create_Marquee()

;####################################################

;Here we block *Mouse* input, except the mouse movement and the wheel button scrolling.
_BlockInputEx(2, "{MMOVE}|{MWSCROLL}")

; Now you can run your script here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
While 1
    Sleep(100)
WEnd

Func _Create_Marquee()

    $hGUI = GUICreate("ScrollingMarquee", $aMarquee_Coords[2], $aMarquee_Coords[3], $aMarquee_Coords[0], $aMarquee_Coords[1], $WS_POPUPWINDOW, $WS_EX_TOPMOST, WinGetHandle(AutoItWinGetTitle()))

    ; Here we set the scrolling requirements
    _GUICtrlMarquee_SetScroll(0, Default, "left", Default, 120)
    ; Here we set the display colours and font
    _GUICtrlMarquee_SetDisplay(1, 0x000000, 0x99CCFF, 26, "Comic Sans MS")
    ; And here we create the marquee itself
    _GUICtrlMarquee_Create($sLabel, 0, 0, $aMarquee_Coords[2], $aMarquee_Coords[3])

    GUISetState()

EndFunc

Func _Find_Taskbar(ByRef $aMarquee_Coords)

    ; Find systray and get size
    Local $iPrevMode = AutoItSetOption("WinTitleMatchMode", 4)
    Local $aTray_Pos = WinGetPos("classname=Shell_TrayWnd")
    AutoItSetOption("WinTitleMatchMode", $iPrevMode)

    ; If error in finding systray
    If Not IsArray($aTray_Pos) Then Return SetError(1, 0)

    ; Determine position of taskbar
    If $aTray_Pos[1] > 0 Then
        ; Taskbar at BOTTOM so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - $aTray_Pos[3] - 60
        EndIf
    ElseIf $aTray_Pos[0] > 0 Then
        ; Taskbar at RIGHT so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth - $aTray_Pos[2]
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    ElseIf $aTray_Pos[2] = @DesktopWidth Then
        ; Taskbar at TOP so coords of the marquee are
        $aMarquee_Coords[0] = 0
        $aMarquee_Coords[2] = @DesktopWidth
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = $aTray_Pos[3]
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    ElseIf $aTray_Pos[3] = @DesktopHeight Then
        ; Taskbar at LEFT so coords of the marquee are
        $aMarquee_Coords[0] = $aTray_Pos[2]
        $aMarquee_Coords[2] = @DesktopWidth - $aTray_Pos[2]
        If $fMarquee_Pos = "top" Then
            $aMarquee_Coords[1] = 0
        Else
            $aMarquee_Coords[1] = @DesktopHeight - 60
        EndIf
    EndIf

EndFunc

Func _Quit()
    Exit
EndFunc

All clear? You know what to do if it is not! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Awesome! It's working. One more question (hopefully :D). Can I also make the script end because of an error? I'm having the script create some formulas in excel and it is possible on occasion for it to return a formula error. The window would be exactly as such ("Formula Error",""). Not sure how to use the "_Quit" function for that.

Link to comment
Share on other sites

  • Moderators

Jadog,

You could check for such a window from time to time using an Adlib function: :oops:

; Set up the Adlib function
AdlibRegister("_Check_Error", 30000) ; will run the function every 30 secs

Func _Check_Error()
    If WinExists("Formula Error","") Then
        _Quit()
    EndIf
EndFunc

That should do the trick. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Ok, it seems to be working good, except it doesn't want to scroll properly (probably because my script requires too much out of my poor computer). It scrolls only to the first word or so. Maybe we could have it just show in the middle instead of scrolling?

* Edit:

Nevermind, it seems to be working after all. One of the things I have my script doing is running a macro in excel and during that time it seems to stop the marquee. But after it keeps scrolling.

Edited by Jadog
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...