Since the start of this work, I found that my own knockup is significantly increased. The daily work is based on programming and Type in all kinds of things, or in the MSN Messenger "pen", so I think my keyboard is It can't bear it, the "Alt" button is somewhat sticky. So I plan to buy a Microsoft human engineering keyboard in the short term, which should be beneficial to my wrist and fingers. Suddenly I thought, I really want to know how much I tap the keyboard every day. After searching Google didn't find anything related, I wrote a small program with C # to count the number of keystrokes, every time the keyup is a tap:
Use the setwindowshookex function when writing. But after running, I can't find the keyboard in other processes other than this Counter program. I found a KB318804 "How to: set a windows hook in Visual C # .NET", the heart is cold half: inside, "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 ", translated simply said, because the .NET DLL that can not be unmanaged code of The process is called, so .NET cannot write global hooks.
So I am not willing, continue to find, find an article "Global System Hooks in .Net" in Code Project, it can implement global hooks in .NET, the method is the middle clip, Managed DLL <- unmanaged DLL <- Other Processes. This approach is also very easy to understand, nothing more than a layer of interface. I don't like this, the reason and the author of the next article, "But what i dispike there is an unmanaged DLL IN C That Is A Main Part of this Solution. THIS UNMANAGED DLL IN C And a Number of Classes Make It Complicated to Integrate It in My OWN TINY Application.