Extracting a windows form title during global hook events

  • Thread starter Molalla Attenborough
  • Start date
M

Molalla Attenborough

Hello, a little help would be greatly appreciated.
I have implemented a global kb hook class into my vb.net application.
(more info:
Processing Global Mouse and KB Hooks in C#
http://www.codeproject.com/csharp/globalhook.asp)

Anyway, George's hook raises an event in my.net application
whenever a key is pressed. Here is what I need to do -

I want my application to be running in the background.
I want to watch for keypresses in *specific applications*.
Therefore, what I need to do is extract the name of the
current foreground window so I can evaluate it as a string.

So the code would go in here...

Public Sub KeyDown(ByVal sender as object, ByVal e as KeyEventArgs) Handles MyHook.KeyDown
console.writeline("Key pressed was - " + e.keyvalue.tostring)
console.writeline("Key was pressed in application named - " + [INSERT CODE HERE])
End Sub

Remember, my little application does not have the focus.

Thanks!
 
M

Molalla Attenborough

Figured it out using GetForGroundWindow() and GetWindowText from
user32.dll

Thanks!
 

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