Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / input.cs / 1305600 / input.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Provides mouse and keyboard input functionality
//
// History:
// 05/29/2003 : BrendanM ported to WCP
//
//---------------------------------------------------------------------------
using System.Windows.Input;
using System.ComponentModel;
using System.Runtime.InteropServices;
using MS.Win32;
using System;
namespace MS.Internal.Automation
{
//
// Provides internal methods for sending keyboard input
//
internal sealed class Input
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Static class - Private to prevent creation
Input()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
//
// Inject keyboard input into the system
//
internal static void SendKeyboardInput( Key key, bool press )
{
UnsafeNativeMethods.INPUT ki = new UnsafeNativeMethods.INPUT();
ki.type = UnsafeNativeMethods.INPUT_KEYBOARD;
ki.union.keyboardInput.wVk = (short) KeyInterop.VirtualKeyFromKey( key );
ki.union.keyboardInput.wScan = (short) UnsafeNativeMethods.MapVirtualKey( ki.union.keyboardInput.wVk, 0 );
int dwFlags = 0;
if( ki.union.keyboardInput.wScan > 0 )
dwFlags |= UnsafeNativeMethods.KEYEVENTF_SCANCODE;
if( !press )
dwFlags |= UnsafeNativeMethods.KEYEVENTF_KEYUP;
ki.union.keyboardInput.dwFlags = dwFlags;
if( IsExtendedKey( key ) )
{
ki.union.keyboardInput.dwFlags |= UnsafeNativeMethods.KEYEVENTF_EXTENDEDKEY;
}
ki.union.keyboardInput.time = 0;
ki.union.keyboardInput.dwExtraInfo = new IntPtr( 0 );
Misc.SendInput(1, ref ki, Marshal.SizeOf(ki));
}
// Used internally by the HWND SetFocus code - it sends a hotkey to
// itself - because it uses a VK that's not on the keyboard, it needs
// to send the VK directly, not the scan code, which regular
// SendKeyboardInput does.
internal static void SendKeyboardInputVK( byte vk, bool press )
{
UnsafeNativeMethods.INPUT ki = new UnsafeNativeMethods.INPUT();
ki.type = UnsafeNativeMethods.INPUT_KEYBOARD;
ki.union.keyboardInput.wVk = vk;
ki.union.keyboardInput.wScan = 0;
ki.union.keyboardInput.dwFlags = press ? 0 : UnsafeNativeMethods.KEYEVENTF_KEYUP;
ki.union.keyboardInput.time = 0;
ki.union.keyboardInput.dwExtraInfo = new IntPtr( 0 );
Misc.SendInput(1, ref ki, Marshal.SizeOf(ki));
}
#endregion Internal Methods
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
private static bool IsExtendedKey( Key key )
{
// From the SDK:
// The extended-key flag indicates whether the keystroke message originated from one of
// the additional keys on the enhanced keyboard. The extended keys consist of the ALT and
// CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP,
// PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK
// key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in
// the numeric keypad. The extended-key flag is set if the key is an extended key.
//
// - docs appear to be incorrect. Use of Spy++ indicates that break is not an extended key.
// Also, menu key and windows keys also appear to be extended.
return key == Key.RightAlt
|| key == Key.RightCtrl
|| key == Key.NumLock
|| key == Key.Insert
|| key == Key.Delete
|| key == Key.Home
|| key == Key.End
|| key == Key.Prior
|| key == Key.Next
|| key == Key.Up
|| key == Key.Down
|| key == Key.Left
|| key == Key.Right
|| key == Key.Apps
|| key == Key.RWin
|| key == Key.LWin;
// Note that there are no distinct values for the following keys:
// numpad divide
// numpad enter
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
// Stateless object, has no private fields
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Provides mouse and keyboard input functionality
//
// History:
// 05/29/2003 : BrendanM ported to WCP
//
//---------------------------------------------------------------------------
using System.Windows.Input;
using System.ComponentModel;
using System.Runtime.InteropServices;
using MS.Win32;
using System;
namespace MS.Internal.Automation
{
//
// Provides internal methods for sending keyboard input
//
internal sealed class Input
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Static class - Private to prevent creation
Input()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
//
// Inject keyboard input into the system
//
internal static void SendKeyboardInput( Key key, bool press )
{
UnsafeNativeMethods.INPUT ki = new UnsafeNativeMethods.INPUT();
ki.type = UnsafeNativeMethods.INPUT_KEYBOARD;
ki.union.keyboardInput.wVk = (short) KeyInterop.VirtualKeyFromKey( key );
ki.union.keyboardInput.wScan = (short) UnsafeNativeMethods.MapVirtualKey( ki.union.keyboardInput.wVk, 0 );
int dwFlags = 0;
if( ki.union.keyboardInput.wScan > 0 )
dwFlags |= UnsafeNativeMethods.KEYEVENTF_SCANCODE;
if( !press )
dwFlags |= UnsafeNativeMethods.KEYEVENTF_KEYUP;
ki.union.keyboardInput.dwFlags = dwFlags;
if( IsExtendedKey( key ) )
{
ki.union.keyboardInput.dwFlags |= UnsafeNativeMethods.KEYEVENTF_EXTENDEDKEY;
}
ki.union.keyboardInput.time = 0;
ki.union.keyboardInput.dwExtraInfo = new IntPtr( 0 );
Misc.SendInput(1, ref ki, Marshal.SizeOf(ki));
}
// Used internally by the HWND SetFocus code - it sends a hotkey to
// itself - because it uses a VK that's not on the keyboard, it needs
// to send the VK directly, not the scan code, which regular
// SendKeyboardInput does.
internal static void SendKeyboardInputVK( byte vk, bool press )
{
UnsafeNativeMethods.INPUT ki = new UnsafeNativeMethods.INPUT();
ki.type = UnsafeNativeMethods.INPUT_KEYBOARD;
ki.union.keyboardInput.wVk = vk;
ki.union.keyboardInput.wScan = 0;
ki.union.keyboardInput.dwFlags = press ? 0 : UnsafeNativeMethods.KEYEVENTF_KEYUP;
ki.union.keyboardInput.time = 0;
ki.union.keyboardInput.dwExtraInfo = new IntPtr( 0 );
Misc.SendInput(1, ref ki, Marshal.SizeOf(ki));
}
#endregion Internal Methods
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
private static bool IsExtendedKey( Key key )
{
// From the SDK:
// The extended-key flag indicates whether the keystroke message originated from one of
// the additional keys on the enhanced keyboard. The extended keys consist of the ALT and
// CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP,
// PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK
// key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in
// the numeric keypad. The extended-key flag is set if the key is an extended key.
//
// - docs appear to be incorrect. Use of Spy++ indicates that break is not an extended key.
// Also, menu key and windows keys also appear to be extended.
return key == Key.RightAlt
|| key == Key.RightCtrl
|| key == Key.NumLock
|| key == Key.Insert
|| key == Key.Delete
|| key == Key.Home
|| key == Key.End
|| key == Key.Prior
|| key == Key.Next
|| key == Key.Up
|| key == Key.Down
|| key == Key.Left
|| key == Key.Right
|| key == Key.Apps
|| key == Key.RWin
|| key == Key.LWin;
// Note that there are no distinct values for the following keys:
// numpad divide
// numpad enter
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
// Stateless object, has no private fields
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TemplateControlCodeDomTreeGenerator.cs
- WSTrust.cs
- CodeTypeDeclarationCollection.cs
- StickyNoteContentControl.cs
- FrameworkName.cs
- RelationalExpressions.cs
- ObjectItemCollection.cs
- ContainerUtilities.cs
- EmptyControlCollection.cs
- DataGridViewCellPaintingEventArgs.cs
- MetaType.cs
- UserControl.cs
- NameValueConfigurationCollection.cs
- TreeNodeBindingCollection.cs
- WpfMemberInvoker.cs
- ObjectAnimationUsingKeyFrames.cs
- InsufficientExecutionStackException.cs
- SerializationEventsCache.cs
- EntityClassGenerator.cs
- AutomationElement.cs
- SoapFault.cs
- Material.cs
- SBCSCodePageEncoding.cs
- AppSecurityManager.cs
- PrincipalPermission.cs
- TemplatedMailWebEventProvider.cs
- Assembly.cs
- Point.cs
- RegistryDataKey.cs
- InfiniteIntConverter.cs
- RealizationDrawingContextWalker.cs
- Buffer.cs
- MouseGestureConverter.cs
- NotifyCollectionChangedEventArgs.cs
- TemplatePartAttribute.cs
- XmlBuffer.cs
- DesignTimeXamlWriter.cs
- RenderDataDrawingContext.cs
- NumericPagerField.cs
- QilTypeChecker.cs
- TemplateNameScope.cs
- Encoding.cs
- VariableModifiersHelper.cs
- WebPartConnectionsDisconnectVerb.cs
- DataContractJsonSerializerOperationFormatter.cs
- DesignerVerb.cs
- XPathNavigatorException.cs
- DuplicateWaitObjectException.cs
- DesignerAutoFormatStyle.cs
- FunctionQuery.cs
- ResourceContainerWrapper.cs
- ResourceReader.cs
- TabControlToolboxItem.cs
- OracleDateTime.cs
- SendMailErrorEventArgs.cs
- StructuredProperty.cs
- AdRotatorDesigner.cs
- TransformedBitmap.cs
- storepermission.cs
- EntityContainer.cs
- LifetimeServices.cs
- HeaderLabel.cs
- ZipIOExtraFieldZip64Element.cs
- TimeoutValidationAttribute.cs
- KnownTypesProvider.cs
- HttpProfileGroupBase.cs
- ByteAnimationUsingKeyFrames.cs
- UserInitiatedNavigationPermission.cs
- GifBitmapDecoder.cs
- ExpandCollapseProviderWrapper.cs
- BooleanExpr.cs
- Tile.cs
- SafeCryptoKeyHandle.cs
- SerializerWriterEventHandlers.cs
- CollectionsUtil.cs
- SHA1CryptoServiceProvider.cs
- RuntimeConfig.cs
- ToolStripMenuItemCodeDomSerializer.cs
- Visual3DCollection.cs
- RuntimeCompatibilityAttribute.cs
- WebRequest.cs
- QuaternionConverter.cs
- FileSystemInfo.cs
- StandardRuntimeEnumValidator.cs
- BackgroundFormatInfo.cs
- DataGridViewAddColumnDialog.cs
- Process.cs
- XmlSchemaAnnotation.cs
- AlgoModule.cs
- InfoCardProofToken.cs
- UnhandledExceptionEventArgs.cs
- ToolStripRenderEventArgs.cs
- DataServices.cs
- GroupByExpressionRewriter.cs
- LineVisual.cs
- TypeBuilderInstantiation.cs
- EasingFunctionBase.cs
- ControlCodeDomSerializer.cs
- LogicalExpr.cs
- MouseEventArgs.cs