Home All Groups Group Topic Archive Search About

Need to capture all keystrokes to my application

Author
7 Jul 2006 8:35 AM
"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

Author
7 Jul 2006 8:56 AM
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




<Gunnar Syren> schreef in bericht
Show quoteHide quote
news:u30aXBaoGHA.4040@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
Author
7 Jul 2006 12:03 PM
"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

Michel Posseth  [MCP] wrote:

Show quoteHide quote
>
> 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 Syren> schreef in bericht
> news:u30aXBaoGHA.4040@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



--
Author
10 Jul 2006 4:41 PM
Mini-Tools Timm
"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