Jump to content

How to get the selected text without send("^c")?


Recommended Posts

You will never see the MsgBox, even nothing highlighted.

I may be wrong, but it seems to me, that when no text is highlighted, you want CTRL-C to return nothing (an empty variable) so that your MsgBox will display.

Perhaps you just need to clear the clipboard before sending CTRL-C.

There is a couple of methods to do that, the easiest is ClipPut("")

P.S. You should be (troubleshooting) using a second MsgBox in the first section of your If ... Else to see what is in fact on the clipboard.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I may be wrong, but it seems to me, that when no text is highlighted, you want CTRL-C to return nothing (an empty variable) so that your MsgBox will display.

Perhaps you just need to clear the clipboard before sending CTRL-C.

There is a couple of methods to do that, the easiest is ClipPut("")

P.S. You should be (troubleshooting) using a second MsgBox in the first section of your If ... Else to see what is in fact on the clipboard.

Thank you for reply.

In Visual Studio or Sublime Text(PLEASE TRY) or some other coding tools, we send("^c") when we highlighting nothing, we will get a line of text; When we highlighting some text then send("^c"), we get the text highlighted. You will always copy some text, even you did not highlight any text.

Link to comment
Share on other sites

In non-Text Editor programs, pressing CTRL-C when nothing is highlighted, you get nothing in the clipboard. Try it in IE, FF, Chrome, Notepad, any other program you can think of, and see what you get.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

In non-Text Editor programs, pressing CTRL-C when nothing is highlighted, you get nothing in the clipboard. Try it in IE, FF, Chrome, Notepad, any other program you can think of, and see what you get.

 

I said I need my script work in Sublime text and VS, you tell me go try in IE, FF, Chrome...

Edited by wo52616111
Link to comment
Share on other sites

The problem is that the programs you're using it on are the ones with the problem, not AutoIt. Unless there's an API for the programs that allow you to get the selected text without using CTRL-C then you're out of luck.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I believe the problem here is non standard controls and how they deal with the WM_COPY messsage. VS editor has such a control.

If Ctrl and c does not even do what you want then you are indeed in for a world of frustration.

That and the programmatic way will also cause you pain, try it on chrome for example, the active control is not the one where the text actually resides.

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Sleep(5000) ; activate window and select test

ConsoleWrite(copyWithoutCtrlC() & @LF)

Func copyWithoutCtrlC()
    ClipPut("")
    Local $hwnd = WinGetHandle("[ACTIVE]")
    Local $scontrol = ControlGetFocus($hwnd)
    Local $hcontrol = ControlGetHandle($hwnd, "", $scontrol)
    _SendMessage($hcontrol, $WM_COPY)
    Return ClipGet()
EndFunc   ;==>copyWithoutCtrlC

Ctrl and c does not by it's nature return text when nothing is highlighted, it will do nothing and leave whatever was already there, with the VS IDE it gets the text of the current line the cursor is at, because that's how that control, rolls.

So I believe your reasons for not using "^c" are invalid, it is by far the best way there is.

If it is just the sending of keystrokes you dislike then you need to research how that operation works by following the API usage in some fashion or other.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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