Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Global System Hooks in .NET

, 9 Jan 2005
A class library for using *global* system hooks in .NET.
systemhooks.zip
SystemHooks
Documentation
Managed Hooks.chm
ManagedHooks.ndoc
External References
HarnessIt - [Home].url
UnitedBinary.UnitTests.Framework.TestBasis.dll
ManagedHooks
ManagedHooks.csproj.user
ManagedHooksTests
ManagedHooks Tests.htp
ManagedHooksTests.csproj.user
SampleHookingApp
App.ico
SampleHookingApp.csproj.user
Stable Reference
Kennedy.ManagedHooks.dll
SampleHookingApp.exe
SystemHookCore.dll
SystemHookCore
SystemHookCore.def
systemhookscompiledonly.zip
SystemHooksCompiledOnly
Kennedy.ManagedHooks.dll
Managed Hooks.chm
SampleHookingApp.exe
SystemHookCore.dll
// /////////////////////////////////////////////////////////////
// File: KeyboardHookExt.cs	Class: Kennedy.ManagedHooks.KeyboardHookExt
// Date: 2/25/2004			Author: Michael Kennedy
// Language: C#				Framework: .NET
//
// Copyright: Copyright (c) Michael Kennedy, 2004-2005
// /////////////////////////////////////////////////////////////
// License: See License.txt file included with application.
// Description: See compiled documentation (Managed Hooks.chm)
// /////////////////////////////////////////////////////////////

using System;

namespace Kennedy.ManagedHooks
{
	/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/Class/*'/>
	public class KeyboardHookExt : KeyboardHook
	{
		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/KeyboardEventHandlerExt/*'/>
		public delegate void KeyboardEventHandlerExt(System.Windows.Forms.Keys key);

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/KeyDown/*'/>
		public event KeyboardEventHandlerExt KeyDown;
		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/KeyUp/*'/>
		public event KeyboardEventHandlerExt KeyUp;
		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/SystemKeyDown/*'/>
		public event KeyboardEventHandlerExt SystemKeyDown;
		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/SystemKeyUp/*'/>
		public event KeyboardEventHandlerExt SystemKeyUp;

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/ctor/*'/>
		public KeyboardHookExt()
		{
			this.KeyboardEvent += new KeyboardEventHandler(KeyboardHookExt_KeyboardEvent);
		}

		private void KeyboardHookExt_KeyboardEvent(Kennedy.ManagedHooks.KeyboardEvents kEvent, System.Windows.Forms.Keys key)
		{
			switch (kEvent)
			{
				case KeyboardEvents.KeyDown:
					OnKeyDown(key);
					break;
				case KeyboardEvents.KeyUp:
					OnKeyUp(key);
					break;
				case KeyboardEvents.SystemKeyDown:
					OnSysKeyDown(key);
					break;
				case KeyboardEvents.SystemKeyUp:
					OnSysKeyUp(key);
					break;
			}
		}

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnKeyDown/*'/>
		protected virtual void OnKeyDown(System.Windows.Forms.Keys key)
		{
			Fire_KeyDown(key);
		}

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnKeyUp/*'/>
		protected virtual void OnKeyUp(System.Windows.Forms.Keys key)
		{
			Fire_KeyUp(key);
		}

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnSysKeyDown/*'/>
		protected virtual void OnSysKeyDown(System.Windows.Forms.Keys key)
		{
			Fire_SystemKeyDown(key);
		}

		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnSysKeyUp/*'/>
		protected virtual void OnSysKeyUp(System.Windows.Forms.Keys key)
		{
			Fire_SystemKeyUp(key);
		}

		private void Fire_KeyDown(System.Windows.Forms.Keys key)
		{
			if (KeyDown != null)
			{
				KeyDown(key);
			}
		}

		private void Fire_KeyUp(System.Windows.Forms.Keys key)
		{
			if (KeyUp != null)
			{
				KeyUp(key);
			}
		}

		private void Fire_SystemKeyDown(System.Windows.Forms.Keys key)
		{
			if (SystemKeyDown != null)
			{
				SystemKeyDown(key);
			}
		}

		private void Fire_SystemKeyUp(System.Windows.Forms.Keys key)
		{
			if (SystemKeyUp != null)
			{
				SystemKeyUp(key);
			}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael Kennedy
Instructor / Trainer DevelopMentor
United States United States
Michael Kennedy is a founding partner and software engineer at United Binary, LLC (http://www.unitedbinary.com [^]) and he is active in the agile software development community. Michael has been developing software for over 10 years. The last 4 of those years have been solidly focused on .NET development. For more information, please visit his website http://www.michaelckennedy.net [^]
 
In a previous life, Michael was pursuing a fairly successful career in mathematics before he saw the True Light and chose The Way of Programming.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 10 Jan 2005
Article Copyright 2004 by Michael Kennedy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid