473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4072
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
6
by: Valery Polyakov | last post by:
I am drawing lines with a semi-transparent color (alpha=100). When these lines intercept, the color becomes more intense. Is there a way to avoid this, so that I would get the same intensity of...
3
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
5
by: Lucas Tam | last post by:
Hi all, Has anyone done this before? Send client side keystrokes to an application from a webpapge? This maybe more of a Javascript question. In short, I have an application on the client's...
2
by: zak | last post by:
I have some testing to do and I need to put a whole set of data in I want to Record and replay in a loop keystrokes. An idea
2
by: Tim Diggle | last post by:
I'm trying to enter data into a database application running under Citrix ICA Client. I'm doing it from a VBA macro running under Microsoft Excel 2000 (although it may need to be backwardly...
3
by: Gunnar Syren | last post by:
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...
1
by: zanthor | last post by:
Ok... so call me crazy, but I have an idea and I'm looking for where to start... I want to write an application that catches keystrokes and then either redirects them to the in focus window or...
0
by: Gabriel Genellina | last post by:
En Thu, 18 Sep 2008 19:24:26 -0300, Robert Dailey <rcdailey@gmail.com> escribió: Why don't you try it yourself? You may replace builtins.print with your own function too. It's not exactly the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.