Jump to content
Sign in to follow this  

Drag/Drop pixel length?

Recommended Posts


Hello all,

  I'd like to be able to 'select' a string, either in a GUI or on a website by 'highlighting' it with a drag/drop operation.  Ideally then only the characters contained within the 'selected' area would be returned as a string and I could then do some additional processing with them.  Is this possible?

  I know of a way to take a (full) string and measure it's horizontal (X axis) length in pixels...I figure then the characters 'selected' by a drag/drop movement could then be read out of that string...if the pixel length of the drag/drop could be determined.  I am not aware of a way to do that however. 

  For example if there is a string = "This is a sentence of a string", and I click/drag "This is a sentence" then those characters would be returned as a separate string...if possible?  Any suggestions of possible commands that might accomplish this would be appreciated.  I thank you in advance.

Share this post

Link to post
Share on other sites

Try this.

HotKeySet("{ESC}", "_Terminate") ; Press Esc to terminate script
HotKeySet("+!z", "_ShowString") ; Press "Shift-Alt-z" keys to capture selected text.

While 1

Func _ShowString()
    Local $sCB = ClipGet() ; Save existing contents of clipboard.
    Send("^c") ; Send Ctrl-c  to copy selected text to clipboard.
    Local $sSelTxt = ClipGet()
    If $sSelTxt = "" Then
        MsgBox(0, "Selected Text", " No highlighted text", 3)
        MsgBox(0, "Selected Text", $sSelTxt, 3) ; Show selected text
EndFunc   ;==>_ShowString

Func _Terminate()
EndFunc   ;==>_Terminate


Share this post

Link to post
Share on other sites


  Wow thanks for that response...I have not tried it yet but it is a great idea to use the Clipboard, that should work just fine.  Hehe I would not have thought to utilize the Clipboard...clever.  Thank you again.


Share this post

Link to post
Share on other sites

Hi again,

  I gave your method a try and it works quite well...I thank you for that.  I just have a couple of other questions relating to it:

  Instead of your example when you call the function using 'shift/alt/z' presses I use it in a 'mouse right-click' event called function.  When I highlight text within a website it works fine except for the 'context menu' that the browser displays upon a 'right-click' gets in the way a bit...any idea how to suppress the browser context menu...?

  Also for some reason I cannot highlight text that are 'Label' controls within my GUI.  Any control I create using the 'GUICtrlCreateLabel' seems to resist being 'highlighted/selected' using a 'click/drag' over the text string characters...anybody have an idea why this is and how to enable my 'Label' controls to be 'clicked/dragged' to highlight/select the characters within them...???  I thank all in advance for any suggestions.  Regards.


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