Jump to content
Sign in to follow this  
TheReveller

Get selected text

Recommended Posts

TheReveller

Hello,

Is there a way to know what's the currently selected text ?

Thanks.

Share this post


Link to post
Share on other sites
Authenticity

heh, where? like when double clicking or selecting text with the mouse?

You can use AdlibEnable function to call some function that will use Send("^c") and use ClipGet, restore the clipboard with ClipSet or something...

Share this post


Link to post
Share on other sites
TheReveller

I want to show a tooltip when you select a number in any application.

I wish I wouldn't have to tweak it by using the clipboard... That's buggy if you keep doing Ctrl-C while running applications.

In Javascript web programming, you can get the selected text so I guess there should be a way to know what's the selected text in any application by Windows.

Edited by TheReveller

Share this post


Link to post
Share on other sites
Hawkwing

This should work.

HotKeySet ("^{F1}", "gettext")

Local $clipboard

While 1
WEnd


Func gettext ()
    $clipboard = ClipGet ()
    Send ("^c")
    ToolTip (ClipGet ())
    Sleep (5000)
    ToolTip ("")
    ClipPut ($clipboard)
EndFunc

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites
TheReveller

Isn't there something to do like this which doesn't need to send the copy to clipboard action :

http://support.microsoft.com/kb/163434

Sub GetSelectedText()

      On Error Resume Next
      Err.Clear

      Dim oText As TextRange

      ' Get an object reference to the selected text range.
      Set oText = Activewindow.Selection.TextRange

      ' Check to see whether error occurred when getting text object
      ' reference.
      If Err.Number <> 0 Then

         MsgBox "Invalid Selection. Please highlight some text " _
            & "or select a text frame and run the macro again.", _
            vbExclamation
         End

      End If

      ' Display the selected text in a message box.
      If oText.Text = "" Then
         MsgBox "No Text Selected.", vbInformation
      Else
         MsgBox oText.Text, vbInformation
      End If

   End Sub

The info about the currently selected text can be retrieved, so can AutoIt also retrieve it ?

Thanks.

Share this post


Link to post
Share on other sites
TheReveller

Example with IE :

#include<IE.au3>

Global $oText, $oIE

$oIE = _IECreate("http://www.autoitscript.com/forum/index.php?showtopic=92459")

While 1
    $oText = $oIE.document.selection.createrange.text
    ToolTip($oText, Default, Default, Default, Default, 4)
WEnd

Is there a way to get the ActiveWindow object so I could use VBA directly ?

Thanks,

TheReveller

Share this post


Link to post
Share on other sites
MAS

hello

if you want the selected text in edit control

you can use these functions to process on selection

_GUICtrlEdit_GetSel

_GUICtrlEdit_SetSel

_GUICtrlEdit_ReplaceSel

you can find more info on the help file

Good luck :oops:

Edited by MAS

Share this post


Link to post
Share on other sites
PhoenixXL

Hey TheReveller you can use _WinAPI_GetActiveWindow() to get the active window and then use the VBA


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
guinness

A bit late to the party, don't you think hiepxuan2008?

Please refrain from unnecessarily necroing old threads if you can. Thanks.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.