Jump to content

Capturing double clicking in an input box


simbo
 Share

Recommended Posts

Hello All,

I have a GUI with various input boxes. They have the $ES_NUMBER style. Each box starts off empty, then the user can type any number from 1 to 99.

In use, 95% of the time I either type a 1 into the box or leave it emtpy, so I thought it would be natty if double clicking would fill in the 1 for me.

I've searched the help file, but can't find out if it's possible to capture a double click on an input box, can anybody help please?

Thanks in advance,

Simbo

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

$t = TimerInit()
$i = 0
$extrax = 2
$extray = 24

$gui = GUICreate("input double click")
$input = GUICtrlCreateInput("",20,20)
GUISetState()

While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $GUI_EVENT_PRIMARYDOWN
        $extrax = 2
        $extray = 24
        $wpos = WinGetPos("input double click")
        $mpos = MouseGetPos()
        $ipos = ControlGetPos("input double click","",$input)
        If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
            If TimerDiff($t) <= 500 And $i = 1 Then
                GUICtrlSetData($input,"1")
            Else
                $t = TimerInit()
                $i = 1
            EndIf
        EndIf
    EndSwitch
WEnd

You can also use this:

Func _MouseIsOverControl($mpos, $wpos, $ipos, $extrax = 2, $extray = 24)
    If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
        Return True
    Else
        Return False
    EndIf
EndFunc

And here's an example how:

#include <GUIConstantsEx.au3>

$t = TimerInit()
$i = 0
$extrax = 2
$extray = 24

$gui = GUICreate("input double click")
$input = GUICtrlCreateInput("",20,20)
GUISetState()

While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $GUI_EVENT_PRIMARYDOWN
        $extrax = 3
        $extray = 24
        $mpos = MouseGetPos()
        $wpos = WinGetPos("input double click")
        $ipos = ControlGetPos("input double click","",$input)
        If _MouseIsOverControl($mpos, $wpos, $ipos) Then
            If TimerDiff($t) <= 500 And $i = 1 Then
                GUICtrlSetData($input,"1")
            Else
                $t = TimerInit()
                $i = 1
            EndIf
        EndIf
    EndSwitch
WEnd

Func _MouseIsOverControl($mpos, $wpos, $ipos, $extrax = 2, $extray = 24)
    If $mpos[0] > $wpos[0] + $ipos[0] + $extrax And $mpos[1] > $wpos[1] + $ipos[1] + $extray And $mpos[0] < $wpos[0] + $ipos[0] + $extrax + $ipos[2] And $mpos[1] < $wpos[1] + $ipos[1] + $extray + $ipos[3] Then
        Return True
    Else
        Return False
    EndIf
EndFunc
Edited by Info
Link to comment
Share on other sites

Thanks very much Info,

It works perfectly. So we're basically capturing each single click, and checking if another single click in the same place has happened just before?

For my script, that's a adequate solution, although I wonder if there's a way to do it directly? I suppose it was wishful thinking to hope for an "if someRandomCommand($button1=GUIDoubleClick)" type solution!

Best wishes, and thanks again,

Simbo

Link to comment
Share on other sites

So we're basically capturing each single click, and checking if another single click in the same place has happened just before?

Yes.

For my script, that's a adequate solution, although I wonder if there's a way to do it directly? I suppose it was wishful thinking to hope for an "if someRandomCommand($button1=GUIDoubleClick)" type solution!

There could be an easier way to do this but not that I know. You could wait for someone else who knows a better way to capture a double click on control but I think my way is good enough. :(
Link to comment
Share on other sites

Another way:

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

$ret = DllCall("user32", "long", "GetDoubleClickTime")
Global $dblClickTime = $ret[0]
Global $timer, $clicked = False
Global $aInput[4]

$Form1 = GUICreate("Form1", 633, 454, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, '_ende')
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_primary')
$aInput[0] = GUICtrlCreateInput("", 100, 60, 200, 20)
$aInput[1] = GUICtrlCreateInput("", 100, 90, 200, 20)
$aInput[2] = GUICtrlCreateInput("", 100, 120, 200, 20)
$aInput[3] = GUICtrlCreateInput("", 100, 150, 200, 20)
GUISetState(@SW_SHOW)


While 1
    Sleep(100)
WEnd

Func _ende()
    Exit
EndFunc


Func _primary()
    Local $time
    If $clicked Then
        $time = TimerDiff($timer)
    EndIf
    Local $cursor = GUIGetCursorInfo(), $match = False
    Local $ID = $cursor[4]
    For $i = 0 To UBound($aInput) -1
        If $aInput[$i] = $ID Then
            $match = True
            ExitLoop
        EndIf
    Next
    Select
        Case Not $match
            Return
        Case $time > $dblClickTime
            $timer = TimerInit()
            Return
        Case Not $clicked
            $clicked = True
            $timer = TimerInit()
        Case Else
            $clicked = False
            GUICtrlSetData($ID, 1)
    EndSelect
EndFunc

Best Regards BugFix  

Link to comment
Share on other sites

$ret = DllCall("user32", "long", "GetDoubleClickTime")

Ahh, very clever, so this will give me the user's double click time, rather than me imposing one on top.

I've taken this, and Info's scripts and amended my script, and am pleased with the result.

Thanks very much to both of you,

Simbo

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