Jump to content

How to save in a varriable the drag-selected area?


Recommended Posts

Hy programmers, i have a questionn for you:)

How can i save (with the mouse) drag-selected texts, in a varriable if key pressed X?

IF -> Pressed X
THEN
IF THE -> Selected area is TEXT, save the drag-selected text in the "text" variable
ELSE -> MsgBox: "You must select a TEXT"

Is it possible?

I want a program like the windows's Copy and Paste, but if the selected item is not text, then do nothing:)

Edited by ReMoTe04
Link to comment
Share on other sites

HotKeySet("x", "GetData");If you press x then GetData() will be called

While 1;Loop to keep the program running forever
    Sleep(100)
WEnd    

Func GetData()
    Local $text;variable to be used if there is text in the copied string of data
    Send("{CTRLDOWN}" & "c");windows keyboard shortcut to copy selected data to the windows clipboard
    Sleep(100);pause for stability - may not be needed
    Send("{CTRLUP}")
    Local $sData = ClipGet();$sData is a temp variable to push through clipget to see if its text or not
    If @error Then;If Clipget returns an error then open a message box to tell the user
        MsgBox(0,"Message","You must select a TEXT")
    Else $text = $sData;if there is no error then set the clipboard data to $text variable
    EndIf
EndFunc

Try this.

*Edit - added CTRLUP

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

HotKeySet("x", "GetData");If you press x then GetData() will be called

While 1;Loop to keep the program running forever
    Sleep(100)
WEnd    

Func GetData()
    Local $text;variable to be used if there is text in the copied string of data
    Send("{CTRLDOWN}" & "c");windows keyboard shortcut to copy selected data to the windows clipboard
    Sleep(100);pause for stability - may not be needed
    Local $sData = ClipGet();$sData is a temp variable to push through clipget to see if its text or not
    If @error Then;If Clipget returns an error then open a message box to tell the user
        MsgBox(0,"Message","You must select a TEXT")
    Else $text = $sData;if there is no error then set the clipboard data to $text variable
    EndIf
EndFunc

Try this.

THANKS :)

Link to comment
Share on other sites

Shoot I did forget the ctrlup. I like John One's suggestion better. Replace the following:

    Send("{CTRLDOWN}" & "c");windows keyboard shortcut to copy selected data to the windows clipboard     
    Sleep(100);pause for stability - may not be needed

With this:

Send("^c")

or else windows wont release the ctrl button.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • 1 year later...

I know this is an older post, but wanted to say thank you.

Also, a findings for other's that are new to Auto IT like myself;

I found I had to move the line: "$text = $sData;if there is no error then set the clipboard data to $text" down a line, leaving "Else" on the line above, to work. 

Otherwise there's an error for illegal command.

Also, found out that you can't use the 'x' key, so turned this to [ALT]+[x].

Also, found out the script would never end, so added the terminate hotkey via [ALT]+[ESC]

HotKeySet("!{x}", "GetData");If you press x then GetData() will be called
HotKeySet("!{ESC}", "Terminate") ;Exit from the script/program <Alt>+<Esc>.

While 1;Loop to keep the program running forever
    Sleep(100)
WEnd



Func GetData()
    Local $text;variable to be used if there is text in the copied string of data
    Send("{CTRLDOWN}" & "c");windows keyboard shortcut to copy selected data to the windows clipboard
    Sleep(100);pause for stability - may not be needed
    Send("{CTRLUP}")
    Local $sData = ClipGet();$sData is a temp variable to push through clipget to see if its text or not
    If @error Then;If Clipget returns an error then open a message box to tell the user
        MsgBox(0,"Message","You must select a TEXT")
     Else
        $text = $sData;if there is no error then set the clipboard data to $text variable
    EndIf

 EndFunc



 Func Terminate()
    Exit ;Exit the script/progam.
EndFunc   ;==>Terminate

 

 

Edited by -Pete
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...