copy selected text from any application

hi,

How do you copy a selected text from any application?

regards
LVL 3
MutsopAsked:
Who is Participating?
 
sarabandeCommented:
yes, i mean standard dragging and dropping. you could make it that a user selects the number and drags it with the mouse over an icon in the taskbar, then you open a window and let the user drop the number into a control. the mouse cursor would turn to a + symbol as it is with many applications.

Sara
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
MutsopAuthor Commented:
euhm I don't quite get your response... This is just a basic SetText/GetText which only works with the current application.

I want to copy the selected text from ANY application ( whether it is word, excel, Firefox, chrome, notepad, .... ).
0
 
dsineCommented:
if you are trying to access the selected text in another application am afraid that is not possible afaik. You can access clipboard so if someone copies items from other applications this might/is available to you.
0
 
MutsopAuthor Commented:
For further explenation:

What I want is when I selected a text (which in my case would be a phone number) and press Ctrl+W it would call that number using the TAPI library
0
 
dsineCommented:
applications like cisco click to call etc have to register with the applications for them to work. there is some literature online that suggests using accessibility features to look at texts etc in other apps. but am afraid my knowledge on teh subject is limited.
0
 
MutsopAuthor Commented:
how about simulating Ctrl+C press? How can this be done
0
 
dsineCommented:
perhaps.. some onlien documentation on that.

http://inputsimulator.codeplex.com/
0
 
CodeCruiserCommented:
Did you look at http:#37243173 ?
0
 
MutsopAuthor Commented:
K so after reading a coupld of articles I came created following code:
Public Class Main
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    Private Sub TimerHotKey_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerHotKey.Tick
        CheckForHotKeys()
    End Sub

    Public Sub CheckForHotKeys()
        If GetAsyncKeyState(Keys.ControlKey) And GetAsyncKeyState(Keys.B) Then
            SendKeys.Send("^c")
            'If TypeOf (Clipboard.GetText) Is String Then
            TextBoxNumber.Text = Clipboard.GetText
            'Else
            MessageBox.Show("Geselecteerde tekst is geen geldige String")
            'End If
        End If
    End Sub
End Class

Open in new window


But I get following error:
"A call to PInvoke function 'Tapi.Business!Tapi.Business.Main::GetAsyncKeyState' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

any ideas what it might be?
0
 
sarabandeCommented:
to retrieve the text of a control in another process, send a WM_GETTEXT message to the hwnd of the control.

the hwnd of the current control could be get by calling GetForegroundWindow.


Sara
0
 
MutsopAuthor Commented:
@sarabande: "retrieving a text of a control in another process": Would it work for any program? Like the Office programs, browsers, ...

If not is there a way that anybody can help me out with previous problem? ID: 37243464

thanks
0
 
sarabandeCommented:
it would work with all programs which use standard windows text controls for the selected text. so if the user selected text in a chart or grid or even an image it would not work.

you could try whether it works by calling winapi function GetForegroundWindow. if it returns hwnd not zero you could check with spy whether it is the window you were looking for.

Sara
0
 
sarabandeCommented:
when the user selects text in a word document or an excel sheet you hardly will get that selection using windows api (you could make a screenshot image and analyse using ocr ...). but for those programs and also the browsers you could provide add-ons which would do what you want. so after detecting the key-stroke you could check which application is in the foreground and you would try to receive text from text control only if it is not one of the known applications where you provided an add-on.

Sara
0
 
MutsopAuthor Commented:
So simulating a Ctrl-c wouldn't work? That doesn't really make any sense.
0
 
sarabandeCommented:
manipulating key-input of another application only works with a hook. installing a hook requires admin privileges for good reasons. you surely don't want yourself another program monitoring your keys while typing a pin or tan for online banking.

Sara
0
 
sarabandeCommented:
note, most programs would have customization such that to start a macro using a key-combination, for example ctrl+w. they also would allow to give ctrl+w the same meaning as ctrl+c.

Sara
0
 
MutsopAuthor Commented:
Well, the application will only be used inside our company.
The idea was to make some sort of skype number calling possibility. But instead that the number is reconized automaticly, the user has to press Ctrl-b to call a selected number.

As most phonenumbers are retrieved from browsers (other company websites) or pdf/word templates, simulating Ctrl-c would be the best choice.

as if we needed to istall an addon for IE, FF, Chrome, Word, Adobe Reader, it would take a hell of a long time.
0
 
sarabandeCommented:
as told you could install a global hook which catches the ctrl+b. it is also possible for most keyboards to define new key-combinations. and i remember that there are tools - at least in older windows versions - which support global accelerators which would do what you want.

i personally don't like such manipulations cause with the time their existence and reasons tend to become unknown. so new users or users who don't use that feature may try to use the ctrl+b for other reasons or have a program where the ctrl+b has other meaning and that would fail and there is no one who could help them.

Sara
0
 
sarabandeCommented:
for the skype feature you could implement the drop part of drag-and-drop into your application. that way users could select the number and drag it with the mouse to your app, same as they could do it within the browser.

Sara
0
 
MutsopAuthor Commented:
drag-and-drop? Is it a ToolBox element? as I can't seem to find it.
Or do you mean simply dragging and dropping it in a textbox?
0
 
MutsopAuthor Commented:
I guess I should use the drag and drop :)
I hoped though for the Ctrl-c to work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.