473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4092
http://groups.google.com/groups?sour...+keyboard+hook
--
_______________ _____
Klaus H. Probst, MVP
http://www.vbbox.com/

"John" <jo*********@pu rsca.com> wrote in message
news:OG******** ******@TK2MSFTN GP09.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*********@pu rsca.com> wrote in message news:<OG******* *******@TK2MSFT NGP09.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******@mvisi ontechnology.co m> wrote in message
news:6f******** *************** ***@posting.goo gle.com...
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*********@pu rsca.com> wrote in message

news:<OG******* *******@TK2MSFT NGP09.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.mi crosoft.com> wrote in message
news:XD******** *****@cpmsftngx a06.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
4991
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 when the program is run on the backround and not as the primary task. What I would like to have is a same sort of function that would also work when the program is being run on the background. I'm trying to implement a program that would listen...
6
1802
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 color? Thanks a lot.
3
9027
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 sending the keystrokes escapes me at the moment. Is there any material online that describes the process of sending keystrokes to a console app?
5
2728
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 desktop that needs to communicate with an ASP.NET application. The only interface into the application are keystrokes and DDE.
2
1644
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
10213
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 compatible with '97). I'm doing this by using appactivate to activate the database application, then sendkeys to send strings of data and tab characters to fill up a series of data fields. Now, this works if Excel is running under Citrix, but if...
3
5053
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 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...
1
3743
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 another window based on some simple rules... in some cases the keystrokes would need to be sent out to multiple windows. I've done part of this in the past using a C++ application to hook the Win32 keyboard API and dispose of unwanted keystrokes...
0
1052
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 same thing, but given your request "intercepting things send to print() before they're sent to sys.stdout" it may be more adequate. --
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.