Real Challenge!! Capture KeyPress and Text from other Applications

D

DraguVaso

Hi,

For a telephony-application I need the following:

When the user presses F10 in whichever application (Word, Excel, Notepad,
Custom made Applications, ...) my program has to capture this, and go look
in that application and select the telephone-number the user has put his
cursor on.

Is this possible? And if yes: how do I have to do this? Basicly my
application should be able to handle KeyPress-events in the Current active
Application, and than read the word/number on which the cursor is positioned
there...

Any help/hints/tips/explanations would really be appreciated! Thansk a lot
in advance!
 
F

Fitim Skenderi

Hi DraguVaso,

To capture key events form other apps you need to set a system wide keyboard
hook. This will enable you to get all the keyboard events from any
application.

The second thing is, after you capture the key event, your app needs to ask
shell to get the handle of active window of active app, the you can do
whatver you need by sending windows messages to that window (any control
that has a handle).

hope this helps

Fitim Skenderi
 
H

Herfried K. Wagner [MVP]

* "DraguVaso said:
When the user presses F10 in whichever application (Word, Excel, Notepad,
Custom made Applications, ...) my program has to capture this, and go look
in that application and select the telephone-number the user has put his
cursor on.

Keyboard hook:

<URL:http://www.developer.com/net/net/article.php/11087_2193301_1/>

You can get the text with p/invoke on 'SendMessage' + 'WM_GETTEXT'.
Notice that you will need some other Windows API function too to get it
work.
 
C

CJ Taylor

Alright, now I'm confused here. Now I've been trying to understand the
windows API pretty extensivly latley, in which case if you remember I was
talking to Tom Shelton about global hooks on the mouse.

How is this different from the mouse global hook. I understand I can't
write a mouse global hook in .NET but I can write a keyboard global hook?
Is that correct? Or am I not fully understanding this article.

Thanks,
CJ
 
D

DraguVaso

Thansk both.
I'm able to get the event when the F10 is pressed, I'm also able to get the
name of the Caption of that application.
But what doesn't work is the text on which the cursos is positioned.

It should be something like this I guess, but I an't get it to work :-(
Dim txtlen As Long

Dim txt As String

If window_hwnd = 0 Then Exit Function

txtlen = SendMessageLong(window_hwnd, WM_GETTEXTLENGTH, 0, 0)

txt = String(txtlen + 1, Chr(0))

Call SendMessageByString(txtlen, WM_GETTEXT, txtlen + 1, txt)

Anybody can help me with it?

thanks, pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top