Jump to content

Detect if any text is marked.


Bitten
 Share

Recommended Posts

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.

Link to comment
Share on other sites

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 8 months later...

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