Jump to content

Gui button click timed


Recommended Posts

THANKS ALL, A SOLUTION NOW FOUND! solution

WOULD YOU BELIEVE, another solution (possibly the best yet - exactly what I originally wanted)

PLEASE NOTE - I've added another section of code (for $num) to the original, hope it makes things clearer.

Please Help Me!

This is an issue (or related) that I've come across many times, and in the past I've settled for a work-a-round, but this time I would really like a solution. And YES I HAVE SEARCHED THE HELP FILE and THE FORUM. One suggestion here for the support forum (I guess it may have been said before, if so I second it), it would be much easier to perform searches, if previous topics where in categories ... even if those categories were as simple as - Buttons, Checkboxes, Messages, Events, GUI, etc. It is very difficult searching the forum at times - very much a hit'n'miss affair ... so hard to know the right search phrases or words, so categories would at least narrow the search result range.

I need help with getting the time a gui button is held down for?

I've tried many different methods - primarydown, etc, but have had no luck. Every event relating to controls on a gui, don't seem to occur until after the primaryup event.

Basically I want to update a stored value, depending on how long a user clicks a button ... in other words if a user clicks on a button (on a gui) for longer than (say) 3 secs, then they want to update the stored default, otherwise they just want to apply the currently stored default. This is a way around having to add an extra button, so the user can change a default.

Here is an extract of the code from my program - this being one of the variations that almost worked -

#include <GuiConstants.au3>

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $GUI_EVENT_PRIMARYDOWN
        If $cnt = "" Then $begin = TimerInit()
   ;MsgBox(0, "$GUI_EVENT", "PRIMARYDOWN")
    Case $cnt = 1
        $cnt = ""
        $diff = TimerDiff($begin)
   ;MsgBox(0, "Time Mouse Down", $diff)
        If $diff > "3000" Then
            IniWrite($inifle, "Line Count", "default", $new)
            GUICtrlSetData($Input_rn, $new)
            GUICtrlSetData($Button_11, $new)
        EndIf
        $begin = ""
    Case $msg = $Button_11
   ; Set Line Count to $num
        $cnt = 1
        $new =GUICtrlRead($Input_rn)
        $num = IniRead($inifle, "Line Count", "default", "")
        GUICtrlSetData($Input_rn, $num)
    Case Else
   ;;;
    EndSelect
WEnd
Exit

Any suggestions, solutions will be greatly appreciated!

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Moderators

You'll probably need to look at _IsPressed() and ControlGetPos()

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You'll probably need to look at _IsPressed() and ControlGetPos()

Thanks SmOke_N

I've just had a quick look (had to enable the beta helpfile), and _IsPressed() may do the job, but I'm not sure how ControlGetPos() would be relevant - as I'm not moving the mouse or a button, only clicking and holding the mouse button down for a few secs. But I'll keep pondering just in case.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

You'll probably need to look at _IsPressed() and ControlGetPos()

I've tried what you suggested, but I can't see a way around the issue of GUI events, happening only after you release your mouse button ... I need an event to happen, while the mouse button is still held down (the event is the intiation of a timer). I added a little more code relating to a variable call - $num, from the ini file, so that the button always has a number on it ... just in case it was misunderstood, what I'm trying to do.

Basically, I think I need a way for an event to happen on mousedown (or primarydown), when it is clicking on Button 11. In other words, I need the GUI to report an event on mousedown not mouseup (which is what it usually does).

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

far as I know you won't get a notification until the mouse is released, might try something different, like click and double click i.e.

#include <GUIConstants.au3>
#NoTrayIcon
Global Const $WM_COMMAND = 0x0111
Global Const $BN_CLICKED = 0
Global Const $BN_DOUBLECLICKED = 5

$gui = GUICreate("Buttons", 300, 300, 302, 218, -1, $WS_EX_TOPMOST)
$button1 = GUICtrlCreateButton("test button", 10, 10, 120, 25)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = _HiWord($wParam)
    $nID = _LoWord($wParam)
    $hCtrl = $lParam
    Switch $nID
        Case $button1
            Switch $nNotifyCode
                Case $BN_CLICKED
                    ConsoleWrite(_DebugHeader("Button Click"))
                Case $BN_DOUBLECLICKED
                    ConsoleWrite(_DebugHeader("Button Double Clicked"))
            EndSwitch
    EndSwitch
EndFunc   ;==>MY_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

Func _DebugHeader($s_text)
    Return _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF
EndFunc   ;==>_DebugHeader

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

far as I know you won't get a notification until the mouse is released, might try something different, like click and double click i.e.

Switch $nNotifyCode
                Case $BN_CLICKED
                    ConsoleWrite(_DebugHeader("Button Click"))
                    MsgBox(262144, "Clicked", "Button Click")
                Case $BN_DOUBLECLICKED
                    ConsoleWrite(_DebugHeader("Button Double Clicked"))
                    MsgBox(262144, "Clicked", "Button Double Click")
            EndSwitch
Thanks gafrost

I gave your code a go, and because I only have the latest beta as a context menu option (compile / run), I couldn't get it to run in Scite, so I added Msgbox's where you have ConsoleWrite's. Everything worked mostly ok after adding an ontop element, but a double click results in both single & double dialogs appearing - other than that it appears to be a possibility ... though I really don't want to use doubleclick, if it's possible to use my original idea. I know you are a lot cleverer than I, so is there a way to change the GUI's standard settings, so that it reacts to a click, rather than a click release ... this would be a sort of blanket approach, but at least it would be a starting point.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I've now finished my program - Script Templates v2.1, and will be uploading it shortly. Lamentably it does not contain a solution to my request above, only a work-a-round. I thank all that responded, and all that tried for a solution. In the end I went with the original work-a-round of another (though small) button - this is not ideal, and doesn't look the nicest, but what the heck ... it works!

I toyed with a message box prompt - to avoid using another button, but felt that was too clunky and annoying!

I tried using all the ideas mentioned above, but they were unsatisfactory (may be my lack of programming skill).

I tried using an Updown that hid the linked Input (20 x 20), as a sort of 2 button representation - but using less space. Actually this idea almost worked, as the Updown imitates the Button property I wish existed ... while held down/depressed an event occurs. The only missing element was that I wanted a number to be visible, and obviously you cannot place text on an Updown ... I didn't really want to use an Updown anyway, as it's elements are much smaller to aim for with the mouse.

I'm still open to ideas, so please feel free to reply anytime!

I'm also going to add a couple of requests to the Ideas Lab.

1) An extended property for buttons, that allows an event not unlike an Updown one, to occur while the button is depressed (on a GUI).

2) Add a few more extended properties for Updowns - [a] specify a leading number of zeros - which would be very handy i.e. 001, 033, 100 (all for a 2 leading zero's setting), and A to Z incrementation, with numerical entry prevention, and [c] extend the limit range of incremented numbers i.e. up to 99999999 (this is to deal with the 8 characters of the 8.3 dos renaming convention for a program I'm developing).

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

How about this:

#include <GuiConstants.au3>
#include <Array.au3>

Opt("MouseCoordMode", 2)

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)
GUICtrlSetState($Button_11, $GUI_DISABLE)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $GUI_EVENT_PRIMARYDOWN
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
                
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) Then
            $begin = TimerInit()
        Else
            $begin = 0
        EndIf
        
    Case $msg = $GUI_EVENT_PRIMARYUP
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
        
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) Then
            $diff = TimerDiff($begin)   
        Else
            $diff = 0
        EndIf
        
        If $diff > "3000" Then
;Button pressed > 3s
            IniWrite($inifle, "Line Count", "default", $new)
            GUICtrlSetData($Input_rn, $new)
            GUICtrlSetData($Button_11, $new)
        ElseIf $diff > 0 Then
;Button pressed < 3s
        ; Set Line Count to $num
            $cnt = 1
            $new =GUICtrlRead($Input_rn)
            $num = IniRead($inifle, "Line Count", "default", "")
            GUICtrlSetData($Input_rn, $num)
        EndIf
    Case $msg = $Button_11


    Case Else
    ;;;
    EndSelect
WEnd
Exit

Unfortunately it only works on disabled buttons. Otherwise the button event precludes the Primaryup-Message.

I would simply replace the button with an image of the button to avoid confusing the users :)

Hope it helps, E.

Link to comment
Share on other sites

How about this:

Thanks Ebenezer

You certainly win first prize so far, and it almost did the trick?

I think I could live with the disabled, etc option, but on several tests, when I didn't click the button for quite long enough, and then did click it long enough, and if the number had meanwhile changed, it would use the number from the session where I didn't click quite long enough.

I need to look more closely at what you've coded, because it certainly has potential.

GREAT STUFF!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Sorry about this - did it in a bit of a hurry :">

The timer variables weren't properly reset so you could get odd results on multiple tries.

I hope this will work better:

#include <GuiConstants.au3>

Opt("MouseCoordMode", 2)

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)
GUICtrlSetState($Button_11, $GUI_DISABLE)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
    Case $msg = $GUI_EVENT_PRIMARYDOWN
        $begin = -1
        $diff = -1
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
                
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) Then
            $begin = TimerInit()
        EndIf
        
    Case $msg = $GUI_EVENT_PRIMARYUP
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
        
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) AND $begin <> -1 Then
            $diff = TimerDiff($begin)   
        
            If $diff > "3000" Then
;Button pressed > 3s
;~              MsgBox(0, "", $diff)
                IniWrite($inifle, "Line Count", "default", $new)
                GUICtrlSetData($Input_rn, $new)
                GUICtrlSetData($Button_11, $new)
            ElseIf $diff > 0 Then
;Button pressed < 3s
            ; Set Line Count to $num
;~              MsgBox(0, "", $diff)
                $cnt = 1
                $new =GUICtrlRead($Input_rn)
                $num = IniRead($inifle, "Line Count", "default", "")
                GUICtrlSetData($Input_rn, $num)
            EndIf
        EndIf
        
    Case Else
    ;;;
    EndSelect
WEnd
Exit

:)

Link to comment
Share on other sites

Sorry about this - did it in a bit of a hurry :

The timer variables weren't properly reset so you could get odd results on multiple tries.

I hope this will work better:

Once again, thanks Ebenezer,

I still had the same errors, and what's more the thing just didn't work right a lot of the time.

I modified some of the code, and now it seems to work right every time.

The modified code was in this section -

Case $msg = $GUI_EVENT_PRIMARYUP
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
        
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) AND $begin <> -1 Then
            $diff = TimerDiff($begin)   
            
            If $diff > 3000 Then
;Button pressed > 3s
;~               MsgBox(0, "", $diff)
                $new =GUICtrlRead($Input_rn)
                IniWrite($inifle, "Line Count", "default", $new)
               ;GUICtrlSetData($Input_rn, $new)
                GUICtrlSetData($Button_11, $new)
            ElseIf $diff > 0 Then
;Button pressed < 3s
           ; Set Line Count to $num
;~               MsgBox(0, "", $diff)
               ;$cnt = 1
               ;$new =GUICtrlRead($Input_rn)
                $num = IniRead($inifle, "Line Count", "default", "")
                GUICtrlSetData($Input_rn, $num)
            EndIf
        EndIf

Now I just have to figure a way round the disabling element ... that was very clever by the way!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

With Ebenezer's coding and my little mod, we nearly had a complete solution for this!

All we needed was for the button to not look disabled, and it would have been sweet!

I tried several things with labels, etc to stop it looking so disabled, but without success!

Another request in the Ideas Lab I guess?

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I think I mentioned this solution a few posts earlier (but I still like it :) ).

Just replace the button with a picture. Since the routine goes by coordinates, not the Button-control message this should work fine.

$Button_11 = GUICtrlCreatePic("Button1.jpg", 210, 370, 20, 20)

I admit it could look better but I think that's more a result of my lousy graphic skills than a point against the concept :(

I hope this works. As far as I understand your aims, the button does not need to be labeled, is that right ?

Cheers, E.

Link to comment
Share on other sites

  • Moderators

I think I mentioned this solution a few posts earlier (but I still like it :) ).

Just replace the button with a picture. Since the routine goes by coordinates, not the Button-control message this should work fine.

$Button_11 = GUICtrlCreatePic("Button1.jpg", 210, 370, 20, 20)

I admit it could look better but I think that's more a result of my lousy graphic skills than a point against the concept :(

I hope this works. As far as I understand your aims, the button does not need to be labeled, is that right ?

Cheers, E.

I think I might be following you, but if you had used my suggestion before, this is what I meant (sorry, hadn't been around that much to look here in the past couple of days:
#include <GuiConstants.au3>

Global $IsPressed_Primary
_IsPressedMouseButton($IsPressed_Primary)
    
Opt("MouseCoordMode", 2)

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
    
    If _IsPressed($IsPressed_Primary) Then
        $vCoordinates = ControlGetPos("", "", $Button_11)
        $vMouse = MouseGetPos()
                
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] _
            AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) Then
            $begin = TimerInit()
            
            While _IsPressed($IsPressed_Primary)
                ToolTip(TimerDiff($begin) / 1000, 0, 0) ; This is just an example it can be removed.
                Sleep(10)
            WEnd
            
            If TimerDiff($begin) / 1000 > 3 Then ; 3 = 3 seconds
                IniWrite($inifle, "Line Count", "default", $new)
                GUICtrlSetData($Input_rn, $new)
                GUICtrlSetData($Button_11, $new)
            ElseIf $diff > 0 Then
                $cnt = 1
                $new =GUICtrlRead($Input_rn);What are you doing with this line?
                $num = IniRead($inifle, "Line Count", "default", "")
                GUICtrlSetData($Input_rn, $num)
            EndIf
        EndIf
    EndIf
WEnd
Exit

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc


Func _IsPressedMouseButton(ByRef $IsPressed_Primary)
    Local $ReadMouseReg = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
    If $ReadMouseReg Then
        $IsPressed_Primary = "01"
    Else
        $IsPressed_Primary = "02"
    EndIf
EndFunc
I added a "Primary" check, incase this is used on a computer that has a left handed mouse. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I think I mentioned this solution a few posts earlier (but I still like it :) ).

Just replace the button with a picture. Since the routine goes by coordinates, not the Button-control message this should work fine.

Thanks again Ebenezer

I did note what you said on your first post, however I need the number to be visible on the button, not a .jpg, because the number gets updated. You need to see the number, to know what the current default is.

Valuater has just posted an answer to my request in the Ideas Lab, that looks extremely like the perfect answer ... check it out. I haven't had time to dissect it yet!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I think I might be following you, but if you had used my suggestion before, this is what I meant (sorry, hadn't been around that much to look here in the past couple of days:[autoit]

Hi & Thanks SmOke_N

I did try to use what you said, but probably due to my lack of skill, could not solve my problem.

I however have tried your latest, without much success - the number disappears from both the button and input. I like the visible countdown for checking, but I need to dissect what you've done yet - to see if it's useable.

As I replied to Ebenezer above, I think Valuater has supplied a solution ... but I will see what can be done with your idea.

Once again thanks for taking the trouble .... this applies to all the others to.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Moderators

Your question was about a "button", unfortunately the solution provided in the idea lab was not a button but a work around. The solution I showed does exactly what Ebenezers script did on my computer, but kept the button visible. If his solution worked all but the button being disabled, then mine will do what "you asked" for specifically.

I didn't see a working script that you provided with poor results to go off of, only went of Ebz because you said it was close.

Now don't get me wrong, the label Idea I've used before until we were able to actually draw colored buttons. The idea was brought up in one of Gary's (gafrost's) threads that was hijacked in the scripts and scraps forum a while ago.

Here, as I was typing this I decided to write a UDF to specifically do what I think you were asking, and that way you could put it any where you want.

You had your $new = GUICtrlRead() something variable in the wrong place is why it was left blank on the example I gave, I never checked for programming errors other than that the functionality "I" wrote worked.

#include <GuiConstants.au3>

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

$MyGUI = GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
       
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
    ; GUI has to have a variable name and send the control you want to time.
    ; It can be left out completely (optional parameter) if you just want it to return seconds
    ; Example1:  _ControlClickDownTimer($MyGUI, $Button_11) will return seconds
    ; Example2:  _ControlClickDownTimer($MyGUI, $Button_11, 1) will return Milliseconds
    $DownValue = _ControlClickDownTimer($MyGUI, $Button_11, 1) 
    If $DownValue Then ; Will only go to the else statement if the return was true for the control being pressed at all
        If $DownValue  > 3000 Then ; 3000 = 3 seconds (Changed from seconds, figured you could change that if you wanted.
            $new = GUICtrlRead($Input_rn) ;This line I think was in the wrong place on yours, it was in the else statement
            IniWrite($inifle, "Line Count", "default", $new)
            GUICtrlSetData($Input_rn, $new)
            GUICtrlSetData($Button_11, $new)
        Else
            $num = IniRead($inifle, "Line Count", "default", "")
            GUICtrlSetData($Input_rn, $num)
        EndIf
    EndIf
WEnd
Exit

Func _ControlClickDownTimer($hGUI_Hwnd, $iControlID, $iMilleSeconds = 0)
    $OptMouseMode = Opt('MouseCoordMode', 2)
    Local $aMpos = MouseGetPos(), $aCpos = ControlGetPos($hGUI_Hwnd, '', $iControlID)
    Opt('MouseCoordMode', $OptMouseMode)
    If $aMpos[0] >= $aCpos[0] _
        And $aMpos[0] <= ($aMpos[0] + $aCpos[2]) _
        And $aMpos[1] >= $aCpos[1] _
        And $aMpos[1] <= ($aMpos[1] + $aCpos[3]) Then
        
        Local $ReadMouseReg = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
        If $ReadMouseReg Then
            $IsPressed_Primary = "01"
        Else
            $IsPressed_Primary = "02"
        EndIf
        
        Local $a_Pressed = DllCall('User32.Dll', 'int', 'GetAsyncKeyState', 'int', '0x' & $IsPressed_Primary)
        If Not @error And BitAND($a_Pressed[0], 0x8000) = 0x8000 Then
            Local $iTimer = TimerInit()
            While 1
                $a_Pressed = DllCall('User32.Dll', 'int', 'GetAsyncKeyState', 'int', '0x' & $IsPressed_Primary)
                If @error Or BitAND($a_Pressed[0], 0x8000) <> 0x8000 Then ExitLoop
                ;ToolTip(TimerDiff($iTimer), 0, 0)
                Sleep(10)
            WEnd
            If $iMilleSeconds = 1 Then Return TimerDiff($iTimer)
            Return TimerDiff($iTimer) / 1000
        EndIf
    EndIf
    Return 0
EndFunc
Edit:

Commented out the ToolTip() you can uncomment it if you want to see the timer in action I suppose.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Just an idea for you if you don't want to have an extra button..

I also know you just might be trying to figure this out "just because" so I'm not ignoring your request. Perhaps the overlooked GUIGetCursorInfo() commands could be some help in getting your cursor info for you particularly

with option [4] of the array, great for action to occur on mouseover, right click, left click etc, when combined with "if true AND $var[4] = 3 etc..

anyway this particular example is not what you "wanted" but a suggestion thrown your way

#include <GuiConstants.au3>
$mygui = GUICreate("example", 200, 200)
$enter = GUICtrlCreateButton("enter", 10, 10, 40, 40)

GuiSetState(@SW_SHOW,$mygui)

While 1
    
    $msg = GUIGetMsg()
    $checkID = GUIGetCursorInfo($mygui)
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    
        Case $msg = $enter
        MsgBox(262144, "result", "you preformed a traditional left-click on this button")
        
        Case $checkID[3] = 1 And $checkID[4] = "3"
            msgbox(262144, "result", "you right clicked on this button")
    EndSelect
WEnd

ps..been years since I posted on here, haha I'm probably easily forgotten, so hello.

Edited by Coffee
Link to comment
Share on other sites

Hi 'SmOke_N'

Your question was about a "button", unfortunately the solution provided in the idea lab was not a button but a work around. The solution I showed does exactly what Ebenezers script did on my computer, but kept the button visible. If his solution worked all but the button being disabled, then mine will do what "you asked" for specifically.

I didn't see a working script that you provided with poor results to go off of, only went of Ebz because you said it was close.

You had your $new = GUICtrlRead() something variable in the wrong place is why it was left blank on the example I gave, I never checked for programming errors other than that the functionality "I" wrote worked.

I apologise for that bit of misunderstanding, on my copy some of those things were commented out!

Now don't get me wrong, the label Idea I've used before until we were able to actually draw colored buttons.

The idea was brought up in one of Gary's (gafrost's) threads that was hijacked in the scripts and scraps forum a while ago.

Here, as I was typing this I decided to write a UDF to specifically do what I think you were asking, and that way you could put it any where you want.

I'll check that out when I can, but you'll be pleased to note (I hope), that yours was the solution for this, see my next post. This was developed before your latest post, so I haven't had the chance to evaluate your new code yet.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

As with life, programming is quite often a compromise!

A combination of what Smoke_N suggested, Ebenezer coded, and then Smoke_N re-stated and coded, and then with a bit of re-development by me, did the trick.

I had hoped it could be done without dll calls, and had high hopes with what Valuater coded, but his clever layering of a button with coloured labels, would just not work with what I had in mind - namely I just could not get the text to update on the suedo button (I even attempted control deletion & re-creation, but that didn't work right). I also couldn't get the timing aspect to work with it - possibly I'm just not clever enough, but probably I'm expecting too much.

Anyway thanks to all concerned, and while Ebenezer certainly came up with a solution, it was flawed with the disabled button element, whereas Smoke_N really had the goods, so I give him most of the kudos - THANKS Smoke_N .... FOR PERSEVERING WITH ME & FOR ME!

Here then is the final version, which works faultlessly -

#include <GuiConstants.au3>

Global $IsPressed_Primary
_IsPressedMouseButton($IsPressed_Primary)
   
Opt("MouseCoordMode", 2)

Dim $Button_11, $Input_rn, $Label_rn, $Updown_rn
Dim $begin, $cnt, $Dialog, $diff, $height, $inifle, $new, $width

$inifle = @ScriptDir & "\Template.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

$Dialog = $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS
$width = 430
$height = 450

GuiCreate("Script Templates v2.0", $width, $height, _
            (@DesktopWidth-$width)/2, (@DesktopHeight-$height-30)/2 , $Dialog + $WS_MINIMIZEBOX)

$Input_rn = GUICtrlCreateInput("0", 135, 370, 40, 20)
$Updown_rn = GUICtrlCreateUpdown($Input_rn)
GUICtrlSetLimit($Updown_rn, 99, 0)
$Label_rn = GUICtrlCreateLabel("lines", 180, 373, 30, 20)
$Button_11 = GUICtrlCreateButton("", 210, 370, 20, 20)

$num = IniRead($inifle, "Line Count", "default", "")
If $num = "" Then
    $num = "11"
    IniWrite($inifle, "Line Count", "default", $num)
EndIf
GUICtrlSetData($Button_11, $num)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
       
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
   
    If _IsPressed($IsPressed_Primary) Then
        $vCoordinates = ControlGetPos("Script Templates v2.0", "", $Button_11)
        $vMouse = MouseGetPos()
        $begin = TimerInit()
        If $vMouse[0] >= $vCoordinates[0] AND $vMouse[0] <= ($vCoordinates[0]+$vCoordinates[2]) AND $vMouse[1] >= $vCoordinates[1] _
            AND $vMouse[1] <= ($vCoordinates[1]+$vCoordinates[3]) Then
                While _IsPressed($IsPressed_Primary)
                    Sleep(10)
                    $diff = TimerDiff($begin)
                    If $diff > 1500 Then; more than 1.5 seconds
                        $new =GUICtrlRead($Input_rn)
                        IniWrite($inifle, "Line Count", "default", $new)
                        GUICtrlSetData($Button_11, $new)
                    EndIf
                WEnd
                If $diff < 1500 Then; less than 1.5 seconds
                    $num = IniRead($inifle, "Line Count", "default", "")
                    GUICtrlSetData($Input_rn, $num)
                EndIf
        EndIf
    EndIf
WEnd
Exit

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc


Func _IsPressedMouseButton(ByRef $IsPressed_Primary)
    Local $ReadMouseReg = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
    If $ReadMouseReg Then
        $IsPressed_Primary = "01"
    Else
        $IsPressed_Primary = "02"
    EndIf
EndFunc

Note that I've adapted what happens, so that after a -

1) quick click (not keeping the mouse button down), the default value as seen on the button (from the ini file) is returned to the input/updown box.

2) sustained click (holding/depressing for more than 1.5 seconds), the value in the input/updown box, is returned as the new default, and saved to the ini file, and also updates the button text. I added a nice touch here, in that the text updates visually while the mouse button is still depressed!

and here is a working, but unfinished version of my 'Script Templates v2.2' program, that this was all for.

Script_Templates.au3

As with most of my scripts, they start with the small idea, that I can quickly whip something up to make life a little easier, but quite often grow much bigger than the original intention, so end up being much more complex ... they tend to get re-written several times, and if you are lucky, even get commented, etc, etc. Quite a lot of what is done here, can now be done with the brilliant Snippet Holder in Scite, and in fact I probably wouldn't have even bothered developing this, if I'd been using Snippet Holder at the time.

One thing I've not been disciplined with, is the addition in my scripts, of the correct version of AutoIt, my name & email, and rarely ever a description of the scripts purpose. One of the reasons is because of how my scripts start off (as mentioned above), another is because I just quite often forget to do it (usually because I put it off until later). This program here then, is a way for me to quickly update a lot of my old scripts, as well as have a couple of different templates be easily selected/interchangeable. So for those who are possibly slack like me, ENJOY this program, but BE AWARE of the limitations and the CONSEQUENCES.

It is a given, that you may have to modify this program at need, so please don't complain that it doesn't match or suit something of your own or someone else's making ... just make the mods required. I may consider updating/changing/adding some things!

Some of the dialogs explain what is & what is not supported!

I'm considering adding support for -

1) Lines to retain at top/start of script (Checkbox, Input, Updown).

2) Extra lines for a longer description &/or a 'THANKS:' section.

Here's a link to one of my other posts, that leads to my other posts (did that make sense) -

Autoit Programmer's Aids

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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...