By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,149 Members | 885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,149 IT Pros & Developers. It's quick & easy.

Need to capture all keystrokes to my application

P: n/a
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
Jul 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

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


<Gunnar Syrenschreef in bericht
news:u3**************@TK2MSFTNGP05.phx.gbl...
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

Jul 7 '06 #2

P: n/a
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

Michel Posseth [MCP] wrote:
>
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


<Gunnar Syrenschreef in bericht
news:u3**************@TK2MSFTNGP05.phx.gbl...
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


--

Jul 7 '06 #3

P: n/a
"Gunnar" wrote:
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

--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com

Jul 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.