Jump to content

Drag/Drop pixel length?


 Share

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.

Link to comment
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
    Sleep(100)
WEnd


Func _ShowString()
    Local $sCB = ClipGet() ; Save existing contents of clipboard.
    ClipPut("")
    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)
    Else
        MsgBox(0, "Selected Text", $sSelTxt, 3) ; Show selected text
    EndIf
    ClipPut($sCB)
EndFunc   ;==>_ShowString

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

 

Link to comment
Share on other sites

Howdy,

  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.

Regards

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

 

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