Jump to content

Detect Double Click - Fix Trailing Space After Selection


BinaryBrother
 Share

Recommended Posts

I was taking snippets from around the forums and building something to fix the annoying space after double-clicking on a word.

But then I found "layout.word_select.eat_space_to_next_word" in firefox settings.

So, here's the mess I was experimenting with...

Features, hooked handling of click sequences, instead of _IsPressed, for better performance. Clipboard saving. For some reason, it was only working every other time, so I threw in a messy script restart after each instance. If anyone needs double-click detection, this was the best thing I could aggregate from sources around the forums. Not really my work, just a compilation of other sources.

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $hHook, $hStub_KeyProc, $iEditLog, $Gui

Global $gDoubleClickSpeed = RegRead("HKU\.DEFAULT\Control Panel\Mouse", "DoubleClickSpeed")
Global $gTimer = TimerInit()
Global $gPosOld, $gPosNew
Global $gPreX = 0
Global $gPreY = 0
Global $gClicks = 0
Global $gClipboard_Storage

_Main()

Func _Main()
    OnAutoItExitRegister("Cleanup")
    Local $hmod

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    ; Esc to close the script

    $Gui = GUICreate('An example of interception with a hook', 700, 260, -1, -1, $WS_OVERLAPPEDWINDOW)
    $iEdit = GUICtrlCreateEdit('', 5, 5, 290, 250)
    $iEditLog = GUICtrlCreateEdit('', 300, 5, 390, 250)
    GUISetState(@SW_HIDE)

    Do
    Until GUIGetMsg() = -3
EndFunc   ;==>_Main
;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS, $X, $Y, $tmp, $Delta
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; переход к следующей цепочки хуков в очереди (не срабатывает)
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    ; mouse coordinates X, Y
    $X = DllStructGetData($tKEYHOOKS, "vkCode")
    $Y = DllStructGetData($tKEYHOOKS, "scanCode")

    Switch $wParam

        Case $WM_LBUTTONUP
            ;Left up
            $pos = MouseGetPos() ; Get the position.
            $lTimeDelay = Int(TimerDiff($gTimer)) + 1 ;Get the delay in milli seconds
            $gTimer = TimerInit() ;Start the timer again
            If $gPreX = $pos[0] and $gPreY = $pos[1]  and $lTimeDelay <= $gDoubleClickSpeed Then
                _DoubleClickDetected()
            Else
                ;ToolTip('Left Clicked X: ' & $pos[0] & ', Y: ' & $pos[1])
                $gPreX = $pos[0]
                $gPreY = $pos[1]
            EndIf

        Case Else
            ;WinSetTitle($Gui, '', "X: " & $X & ", Y: " & $Y)
            Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; transition to the next chain of hooks in the queue
    EndSwitch
    GUICtrlSetData($iEditLog, $tmp & @CRLF, 1)
    ; Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; transition to the next chain of hooks in the queue
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)

EndFunc   ;==>Cleanup


Func _DoubleClickDetected()
    $gClipBoard_Storage = ClipGet()
    Send("^c")
    $lClipboard_Content = ClipGet()
    ClipPut($gClipBoard_Storage)
    If $lClipboard_Content = "" or StringLen($lClipboard_Content) = 1 Then Return
    If StringRight($lClipboard_Content, 1) = " " Then
        Send("+{LEFT}")
        Local $sCmdLine = '"' & @ScriptFullPath & '"'
    Run(@AutoItExe & ' ' & $sCmdLine, @ScriptDir, @SW_HIDE)
    Exit
    EndIf
EndFunc   ;==>_DoubleClickDetected

 

SIGNATURE_0X800007D NOT FOUND

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