Sign in to follow this  
Followers 0
Bitten

Detect if any text is marked.

12 posts in this topic

Hi,

I have seen several topics regarding this, but none seems to hold the answer im looking for. Please forgive me if i have missed something.

Im trying to automate part of a system to handle lookups of customer numbers, i want to automate is in a way so that autoit can accept input in the form of selected text if present, if not it should open a dialog window where the user can input the data to search for.

The dialog part is working fine, but i can't seem to find a method for detecting if any text is currently marked. I can't use the clipboard, as this may already contain customer data, thus preventing the dialog from showing.

I have no idea if this is at all possible, but im guessing there might be something in windows that knows if anything is marked..

Any feedback or alternative solutions are welcome.

Share this post


Link to post
Share on other sites



You'll have to provide more info. What type of control are you refering to, containing the potential selection? Use the AU3Info tool to get those infos.

Share this post


Link to post
Share on other sites

Well the text selection could happen in outlook, chrome, firefox, adobe reader, internet explorer.. or any similar program. I was hoping that some part of windows was aware that something was selected somewhere, and was able to tell me.

Share this post


Link to post
Share on other sites

Bitten,

You can use the clipboard - just save the current content before trying to capture a new highlighted area. :)

Run this script. Put something on the clipboard, highlight another area and then press "q" - you will see the original clipboard content appear in the SciTE console and a MsgBox display the new selection (or telling you there is no selection). Once you have closed the MsgBox, the original clipboard content is restored and displayed: ;)

HotKeySet("{ESC}", "On_Exit")

HotKeySet("q", "_Check_HighLit")

While 1
    Sleep(10)
WEnd

Func _Check_HighLit()

    ; Save clipboard contents
    Local $vTemp = ClipGet()
    ; Display for test
    ConsoleWrite("Current contents:" & $vTemp & @CRLF & @CRLF)

    ; See if anything is highlighted by copying it to the clipboard
    Send("^c")
    ; Check if there is anything on the clipboard
    Local $sContent = ClipGet()
    If $sContent Then
        MsgBox(0, "HighLit", $sContent)
    Else
        MsgBox(0, "Nothing", "Dialog to get user input")
    EndIf

    ; Replace previous contents
    ClipPut($vTemp)
    ; Display for test
    ConsoleWrite("Current contents:" & ClipGet() & @CRLF & @CRLF)

EndFunc

Func On_Exit()
    Exit
EndFunc

Any use? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Melba,

Unfortunately, your script wont work, it dosnt take in account that something might already be in the clipboard, and thus, not show the input dialog, or at least thats how its working for me?. I think i may have to make some sort of tracker to track how old the clipboard data is, so it will be able to figure out if its a new selection, or some old stuff.

Edited by Bitten

Share this post


Link to post
Share on other sites

Bitten,

Sorry about that oversight - just add a line to clear the clipboard after you have saved the current contents:

; Save clipboard contents
Local $vTemp = ClipGet()
; Display for test
ConsoleWrite("Current contents:" & $vTemp & @CRLF & @CRLF)
; Empty clipboard
ClipPut("")

Better now? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You know.. that might actually do the trick! Going to test it as soon as a get a minute. It was a lot simpler than what i was expecting.. Awesome! :)

Share this post


Link to post
Share on other sites

Would the ControlCommand() function, with the 'GetSelected' command, work here?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Just a small update. The script Melba suggested works perfectly. Thnx a bunch! :)

Share this post


Link to post
Share on other sites

I have always wondered this, if you use

Local $vTemp = ClipGet()
ClipPut()
ClipPut($vTemp)
it will work when a string or files were selected, but any other data (like image data) will be lost. Any solutions to keeping the image data? Because ClipGet() won't return it


MsgBox(0x40040, "", "Hello Forum!")

Share this post


Link to post
Share on other sites

1RV34,

Take a look at the Clipboard.au3 UDF in the Help file. There are functions there that allow you to retrieve/set the clipboard data in other formats. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi

So that binary data and images won't be lost..when you try to restore

This UDF will help..you restore the clipboard for ALL formats text / images

The clipboard.udf is only half the answer..

Func getselected()

; Save clipboard contents

Local $aClip

_Clipboard_GetAll($aClip)

; Empty clipboard
ClipPut("")

; See if anything is highlighted by copying it to the clipboard
Send("^c")

sleep(100);
; Check if there is anything on the clipboard

Local $sContent = ClipGet()
; see if something highlighted...

; restore old clipboard - including binaries
_ClipBoard_PutAll($aClip)


Return ;
EndFunc
Edited by ozmike

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  
Followers 0