#include <ClipBoard.au3>
#include <SendMessage.au3>
#include <MouseOnEvent.au3>
Global $aMPos = MouseGetPos()
Global $bSelected = False
HotKeySet('{ESC}', '_Exit')
_SetMouseEvents(True)
While 1
If $bSelected Then
$bSelected = False
_SetMouseEvents(False)
$aOld_Clip = _ClipBoard_Remember()
ClipPut('')
Send('^{INS}')
$iTimer = TimerInit()
Do
$sSelText = ClipGet()
If $sSelText <> '' Then
ExitLoop
EndIf
Sleep(10)
Until TimerDiff($iTimer) > 250
_ClipBoard_Restore($aOld_Clip)
If $sSelText Then
ToolTip($sSelText, Default, Default, 'Selected', 1)
AdlibRegister('_ClearToolTip', 3000)
EndIf
_SetMouseEvents(True)
EndIf
Sleep(10)
WEnd
Func _Exit()
Exit
EndFunc
Func _ClearToolTip()
AdlibUnRegister('_ClearToolTip')
ToolTip('')
EndFunc
Func _SetMouseEvents($bSet)
_MouseSetOnEvent_RI($MOUSE_PRIMARYDOWN_EVENT, ($bSet ? '_MousePrimaryDown_Event' : ''))
_MouseSetOnEvent_RI($MOUSE_PRIMARYUP_EVENT, ($bSet ? '_MousePrimaryUp_Event' : ''))
_MouseSetOnEvent_RI($MOUSE_PRIMARYDBLCLK_EVENT, ($bSet ? '_MousePrimaryUp_Event' : ''))
EndFunc
Func _MousePrimaryDown_Event()
$aMPos = MouseGetPos()
EndFunc
Func _MousePrimaryUp_Event($iEvent)
Local $aMPos_Tmp = MouseGetPos()
If $iEvent = $MOUSE_PRIMARYDBLCLK_EVENT Or ($iEvent <> $MOUSE_PRIMARYDBLCLK_EVENT And ($aMPos_Tmp[0] <> $aMPos[0] Or $aMPos_Tmp[1] <> $aMPos[1])) Then
$bSelected = True
EndIf
EndFunc
Func _ClipBoard_Remember()
Local $iFormat, $hWnd = GUICreate('')
If Not _ClipBoard_Open($hWnd) Then
Return SetError(1)
EndIf
Local $aRet[1][2]
Do
$iFormat = _ClipBoard_EnumFormats($iFormat)
If $iFormat <> 0 Then
$aRet[0][0] += 1
ReDim $aRet[$aRet[0][0] + 1][2]
$aRet[$aRet[0][0]][1] = $iFormat
EndIf
Until $iFormat = 0
_ClipBoard_Close()
GUIDelete($hWnd)
For $i = 1 To $aRet[0][0]
$aRet[$i][0] = _ClipBoard_GetData($aRet[$i][1])
Next
Return $aRet
EndFunc
Func _ClipBoard_Restore(ByRef $aClip)
If UBound($aClip, 0) <> 2 Then
Return SetError(1)
EndIf
For $i = 1 To $aClip[0][0]
_ClipBoard_SetData($aClip[$i][0], $aClip[$i][1])
Next
$aClip = 0
Return 1
EndFunc