|
// /////////////////////////////////////////////////////////////
// File: KeyboardTracking.cs Class: Kennedy.ManagedHooks.KeyboardTracking
// 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;
using System.Windows.Forms;
namespace Kennedy.ManagedHooks
{
/// <include file='ManagedHooks.xml' path='Docs/KeyboardTracking/Class/*'/>
public class KeyboardTracking : KeyboardHookExt
{
private bool _controlPressed = false;
private bool _altPressed = false;
private bool _shiftPressed = false;
/// <include file='ManagedHooks.xml' path='Docs/KeyboardTracking/ctor/*'/>
public KeyboardTracking()
{
}
/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnKeyDown/*'/>
protected override void OnKeyDown(System.Windows.Forms.Keys key)
{
bool isSystemKey = SetTrackingState(key, true);
if (isSystemKey)
{
return;
}
base.OnKeyDown(key);
}
/// <include file='ManagedHooks.xml' path='Docs/KeyboardHookExt/OnKeyUp/*'/>
protected override void OnKeyUp(System.Windows.Forms.Keys key)
{
bool isSystemKey = SetTrackingState(key, true);
if (isSystemKey)
{
return;
}
base.OnKeyUp(key);
}
private bool SetTrackingState(System.Windows.Forms.Keys key, bool isDown)
{
switch (key)
{
case Keys.Alt:
_altPressed = isDown;
return true;
case Keys.Control:
_controlPressed = isDown;
return true;
case Keys.Shift:
_shiftPressed = isDown;
return true;
}
return false;
}
/// <include file='ManagedHooks.xml' path='Docs/KeyboardTracking/ControlPressed/*'/>
public bool ControlPressed
{
get
{
return _controlPressed;
}
}
/// <include file='ManagedHooks.xml' path='Docs/KeyboardTracking/AltPressed/*'/>
public bool AltPressed
{
get
{
return _altPressed;
}
}
/// <include file='ManagedHooks.xml' path='Docs/KeyboardTracking/ShiftPressed/*'/>
public bool ShiftPressed
{
get
{
return _shiftPressed;
}
}
}
}
|
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.
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.