468,727 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

Intercepting Keystrokes

Hi,

Can anyone point me out how to intercept the keystrokes from a c#
application that's not a active window? - intercepting the system wide
keystrokes before it hits the target active window?

Thanks!

John

Nov 15 '05 #1
7 3824
http://groups.google.com/groups?sour...+keyboard+hook
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"John" <jo*********@pursca.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
Hi,

Can anyone point me out how to intercept the keystrokes from a c#
application that's not a active window? - intercepting the system wide
keystrokes before it hits the target active window?

Thanks!

John

Nov 15 '05 #2
John:

I've done this in the past by installing a keyboard hook. The
keyboard hook does whatever it needs to do and either passes the
message on the the active application or simply swallows the keys.

Another way to do this is to tie the input queus of the 2 applications
together, but I've not done this w/ .NET assemblies --- only regular
Win32 processes.

I'd go w/ the keyboard hook.

John
"John" <jo*********@pursca.com> wrote in message news:<OG**************@TK2MSFTNGP09.phx.gbl>...
Hi,

Can anyone point me out how to intercept the keystrokes from a c#
application that's not a active window? - intercepting the system wide
keystrokes before it hits the target active window?

Thanks!

John

Nov 15 '05 #3
Will the hook only work for the app that set it. .net hooks don't work
system wide do they?
"John Puopolo" <jp******@mvisiontechnology.com> wrote in message
news:6f**************************@posting.google.c om...
John:

I've done this in the past by installing a keyboard hook. The
keyboard hook does whatever it needs to do and either passes the
message on the the active application or simply swallows the keys.

Another way to do this is to tie the input queus of the 2 applications
together, but I've not done this w/ .NET assemblies --- only regular
Win32 processes.

I'd go w/ the keyboard hook.

John
"John" <jo*********@pursca.com> wrote in message

news:<OG**************@TK2MSFTNGP09.phx.gbl>...
Hi,

Can anyone point me out how to intercept the keystrokes from a c#
application that's not a active window? - intercepting the system wide
keystrokes before it hits the target active window?

Thanks!

John

Nov 15 '05 #4

Hi John,

Thank you for posting in the community!

Based on my understanding, you want to intercept the key stroke of another
application.

========================================
Normally, you can use hook to intercept key stroke in C#, for more
information, please refer to:
"HOW TO: Set a Windows Hook in Visual C# .NET"
http://support.microsoft.com/default...b;en-us;318804

This KB installs mouse hook, you can modify it and use keyboard hook.

But, as you want to intercept another application's key stroke, then a
global hook is needed. In the KB, you will see that:

"Global Hook Is Not Supported in .NET Framework

You cannot implement global hooks in Microsoft .NET Framework. To install a
global hook, a hook must have a native dynamic-link library (DLL) export to
inject itself in another process that requires a valid, consistent function
to call into. This requires a DLL export, which .NET Framework does not
support. Managed code has no concept of a consistent value for a function
pointer because these function pointers are proxies that are built
dynamically."

So you can not get this done in .Net. So you should do it in Win32
environment, please Klaus's suggestion to search in google, there will be a
lot of discussion about get this done in Win32 SDK.

=====================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice weekend!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5
Thanks very much! Does future .NET framework support this?

John

"""Jeffrey Tan[MSFT]""" <v-*****@online.microsoft.com> wrote in message
news:XD*************@cpmsftngxa06.phx.gbl...

Hi John,

Thank you for posting in the community!

Based on my understanding, you want to intercept the key stroke of another
application.

========================================
Normally, you can use hook to intercept key stroke in C#, for more
information, please refer to:
"HOW TO: Set a Windows Hook in Visual C# .NET"
http://support.microsoft.com/default...b;en-us;318804

This KB installs mouse hook, you can modify it and use keyboard hook.

But, as you want to intercept another application's key stroke, then a
global hook is needed. In the KB, you will see that:

"Global Hook Is Not Supported in .NET Framework

You cannot implement global hooks in Microsoft .NET Framework. To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not
support. Managed code has no concept of a consistent value for a function
pointer because these function pointers are proxies that are built
dynamically."

So you can not get this done in .Net. So you should do it in Win32
environment, please Klaus's suggestion to search in google, there will be a lot of discussion about get this done in Win32 SDK.

=====================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice weekend!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

Hi John,

Thanks very much for your feedback.

I am glad my reply make sense to you. Actually, the Hook is a system
related technical, I will show you why global hook is not supported in .Net:

Global hook will inject a dll into another process's space, while the
managed dll will only executive in CLR runtime, so your managed dll will
not work in that process's memory space.

So, I think this support is not due to the .Net Framework, it is limited by
the design of the architecture.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #7

Hi John,

Do you still have any concern? Please feel free to feedback.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Olli Piepponen | last post: by
6 posts views Thread by Valery Polyakov | last post: by
5 posts views Thread by Lucas Tam | last post: by
reply views Thread by Gabriel Genellina | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.