Need to capture all keystrokes to my application

G

Gunnar Syren

I'm trying to implement a macro feature in my application by recording
and playing back keystrokes. At first I thought it would be enough to
catch KeyDown in my main form, but I soon realized that I needed to
catch keystrokes in menues and other forms in my app as well.

I realize I can implement a keyboard hook that catches keystrokes
globally, but I only want the keystrokes that are sent to my
application.

Any suggestions on how to accomplish that?

/Gunnar
 
M

Michel Posseth [MCP]

This is verry easy

just set the keypreview property of your form to true now you catch all
keystrokes on that form with the form`s key events

if this is not enough for you ,, you can also implement a messagefilter
interface

i have once posted an example as an alternative of subclassing the
webbrowser control you can easily convert this to catch and process all
Windows messages
in this situation you wil receive every message sent to the window ( moving
, minimizing , mouse moves , keypress etc etc )
you can find this code here http://www.freevbcode.com/ShowCode.Asp?ID=5635

although i think it is a bit overdone in this situation


regards

Michel Posseth MCP
 
G

Gunnar Syren

Well, Michel, since I need to catch the keystrokes for all forms and
all menues, KeyPreview doesn't do it - that was my first idea. I guess
I'll see if I can adapt your code to suit my purpose.

Thanks,
/Gunnar
This is verry easy

just set the keypreview property of your form to true now you catch
all keystrokes on that form with the form`s key events

if this is not enough for you ,, you can also implement a
messagefilter interface

i have once posted an example as an alternative of subclassing the
webbrowser control you can easily convert this to catch and process
all Windows messages in this situation you wil receive every message
sent to the window ( moving , minimizing , mouse moves , keypress etc
etc ) you can find this code here
http://www.freevbcode.com/ShowCode.Asp?ID=5635

although i think it is a bit overdone in this situation


regards

Michel Posseth MCP



--
 
G

Guest

Gunnar said:
Well, Michel, since I need to catch the keystrokes for all forms and
all menues, KeyPreview doesn't do it - that was my first idea. I guess
I'll see if I can adapt your code to suit my purpose.

Hello Gunnar,

If you need to monitor keyboard input across all forms in your application,
then the IMessageFilter method suggested in the other message is the way to
go.

We offer a .NET component FREE for non-commercial use that will do this for
you:

http://www.mini-tools.com/goto/input
 

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