472,958 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 4055
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.