Jump to content

Help - Get the selected text


xiaozhu
 Share

Recommended Posts

...get the selected text without using the sendkey (ctrl+C) approach...

You did not mention why you do not want to use the "^c" approach. Is is because you cannot get that to work for you - if so, please post the code that you have tried... or perhaps the MS Office clipboard manager is a problem? Anyway, try the little test code below. It uses control plus insert instead of control plus C.
Opt("SendKeyDelay",100)
Run("notepad")
WinWait("Untitled - Notepad")
WinActivate("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")
ControlSetText("Untitled - Notepad","","Edit1","Test text to select.")
ControlSend("Untitled - Notepad","","Edit1","{RIGHT 13}+{RIGHT 6}")
ControlSend("Untitled - Notepad","","Edit1","^{INS}")
Sleep(50)
ControlSend("Untitled - Notepad","","Edit1","{END}{ENTER}^v")
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

No need for an active window for this example.

Opt('SendKeyDelay', 100)
For $i = 9 To 1 Step -1
    Run('Notepad')
    WinWait('Untitled')
    ControlSend('Untitled', '', 'Edit1', 'some text{SHIFTDOWN}{LEFT ' & $i & '}{SHIFTUP}')
    Sleep(500)
    MsgBox(0, 'HighLighted Text', ControlCommand('Untitled', '', 'Edit1', 'GetSelected', ''), 2)
    WinKill('Untitled')
    Sleep(50)
Next
Link to comment
Share on other sites

Thanks for all the replies.

We have an issue tracking system, whenever I see an issue number ( may in an email, in the word document, in some slides ) the normal way I have to do it:

(1) Remember or copy the issue number.

(2) Go to the issue tracking system to track this issue.

I want to write a program to do it automatically. I just need to select the issue number, press the shortcut, then directly go in the tracking system to track this issue.

Using "ctrl+C" is definetely one of the approach, but I notice somebody else post that it is not reliable.

Not sure how to Use ControlCommand and GetSelected. The question is if I use this approach, how to get the controlID of the text that I selected.

Again thank for help.

Link to comment
Share on other sites

Well I cant give you specific code since I don't know how your gui looks like but this should help get you on the right track personally I hate using the mouse. I much rather use keys since they dont change with resolution or window position.

Good luck

HotKeySet("^f", "Copy") ;ctrl d

While 1
    Sleep(100)
WEnd

Func Copy()

Winactivate("your application");selectes your app
;if needed
send("{tab},{tab},..."); sends tab x number or times to get to the approprtiate field
sleep(500); to let the computer catch up, sometimes needed
send("^a")
sleep(500)
send("^c")
sleep(500)
Winactivate("wherever you want to put the info")
Send("{tab},etc...)
send("^v")

EndFunc
Link to comment
Share on other sites

Thanks for all the replies.

We have an issue tracking system, whenever I see an issue number ( may in an email, in the word document, in some slides ) the normal way I have to do it:

(1) Remember or copy the issue number.

(2) Go to the issue tracking system to track this issue.

I want to write a program to do it automatically. I just need to select the issue number, press the shortcut, then directly go in the tracking system to track this issue.

Using "ctrl+C" is definetely one of the approach, but I notice somebody else post that it is not reliable.

Not sure how to Use ControlCommand and GetSelected. The question is if I use this approach, how to get the controlID of the text that I selected.

Again thank for help.

It sounds an awful lot like your issue number comes to you in a non-standardized fashion(since it could be in one of many places)... Because of that it almost seems like you would want something like:

$IssueNumber = InputBox("Enter Issue #", "Type or paste in the issue number and hit OK.")

If $IssueNumber = "" Then Exit

If WinExists("Your Tracking Software") Then
    WinActivate("Your Tracking Software")
    WinWaitActive("Your Tracking Software")
    ;At this point you could either use "Send" commands or "ControlSend/ControlClick etc. commands to plug in the issue number/do whatever.
Else
    MsgBox( 0, "Problem!", "Not seeing the tracking software open... Exiting now.")
    Exit
EndIf

A fancier/neater version of this would probably involve just making a simple little gui (the inputbox is really more than you need) to receive your issue number... And you'll want to check your tracking software with the AutoIt Window Info Tool to see if it uses real controls.. Every software that I've come across (HEAT/Remedy) has not.. so you may hafta rig something up there.

Link to comment
Share on other sites

...We have an issue tracking system, whenever I see an issue number ( may in an email, in the word document, in some slides ) the normal way I have to do it:

(1) Remember or copy the issue number.

(2) Go to the issue tracking system to track this issue....

I use AutoIt to do something just like this many times a day.

...Using "ctrl+C" is definetely one of the approach, but I notice somebody else post that it is not reliable...

Yes, there are some issues with the Windows clipboard - but you can work around them.

...Not sure how to Use ControlCommand and GetSelected. The question is if I use this approach, how to get the controlID of the text that I selected...

The "AutoIt Window Info" tool that comes with the AutoIt install can help you do that, but you would need to get the controlID of the control containing the text... for what you described, this may not be the best route to take.

For my situation, I decided to manually get the number into the Windows clipboard based on whatever method works best for the application that I'm getting it from. Also, I have encountered a Windows OS error telling me that the clipboard could not be emptied - which tells me that it will not accept the new data - this generally requires a system restart. So, all of that rambling just to say that I opted to manually get the number into the OS clipboard and manually deal with any issues that may arise from doing so.

If the OS gives no errors when I send data into the clipboard, then I run my script. In my case, one of the systems that I want to feed this number to is a web based application. I was lucky in that the number is simply apppended to a URL.

I made my little AutoIt script,

left the file as an au3 text/script file,

made a regular OS shortcut to that au3 script file

and then placed the shortcut directly onto my IE links toolbar.

One click on that "link" and the script takes me right to the page of interest.

One way to layout your code is to start with the various settings available to you via the AutoItSetOption function (otherwise known as the Opt function).

One such "Opt function" that I would suggest you always include - at least while working the bugs out of your code, is this one:

AutoItSetOption ("TrayIconDebug", 1)  ;0-offoÝ÷ Ø]z׫)Þ²0ëh"Ùë«íì"Ú0~ߺw-ì)Z)Öj+ZÚ-êÖwîËb¢{·
&k&Þ¶¨­Â®¢Ó©µû§rبʮ¢ÛajܨºwvÚ©àyúèØ^uçÚº[NDz¢èµ©e¡ûaz«¨¶m~éܶ*'²«¨¶Ç­Êjx(¢{hÊ«¢Ø^®X§zÊr^Z§!Ê)ÉúèÇ«µ¨§jeÆ­ì!éݺ"¶^iا©Ýþí­¨¥x,¥§²)íç%èj·S+%w¨}ÊzÖ¤zÇ­ê+¶­jëh×6$s_TrackNumber = StringStripWS(ClipGet(), 8)
...but you may need AutoIt to tab to the field of interest first. A better method is to use one of the various Control... functions; but they only work with certain apps.

Try some code for yourself and if you need help, post that code to this thread.

-hope this helps-

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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