Provides extended data for the event.
Inheritance: System.Windows.Forms.KeyPressEventArgs
Exemplo n.º 1
0
 private static KeyPressEventArgsExt CreateNonChar()
 {
     KeyPressEventArgsExt e = new KeyPressEventArgsExt((char)0x0);
     e.IsNonChar = true;
     e.Timestamp = Environment.TickCount;
     return e;
 }
Exemplo n.º 2
0
 private void InvokeKeyPress(KeyPressEventArgsExt e)
 {
     KeyPressEventHandler handler = KeyPress;
     if (handler == null || e.Handled || e.IsNonChar) { return; }
     handler(this, e);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates <see cref="KeyPressEventArgsExt"/> from Windows Message parameters,
        /// based upon a system-wide hook.
        /// </summary>
        /// <param name="wParam">The first Windows Message parameter.</param>
        /// <param name="lParam">The second Windows Message parameter.</param>
        /// <returns>A new KeyPressEventArgsExt object.</returns>
        internal static KeyPressEventArgsExt FromRawDataGlobal(int wParam, IntPtr lParam)
        {
            if (wParam != Messages.WM_KEYDOWN)
            {
                return CreateNonChar();
            }

            KeyboardHookStruct keyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));

            int virtualKeyCode = keyboardHookStruct.VirtualKeyCode;
            int scanCode = keyboardHookStruct.ScanCode;
            int fuState = keyboardHookStruct.Flags;

            char ch;
            bool isSuccessfull = Keyboard.TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, out ch);
            if (!isSuccessfull)
            {
                return CreateNonChar();
            }

            KeyPressEventArgsExt e = new KeyPressEventArgsExt(ch);
            e.Timestamp = keyboardHookStruct.Time;		// Update the timestamp to use the actual one from KeyboardHookStruct

            return e;
        }
        /// <summary>
        /// Creates <see cref="KeyPressEventArgsExt"/> from Windows Message parameters,
        /// based upon a system-wide hook.
        /// </summary>
        /// <param name="wParam">The first Windows Message parameter.</param>
        /// <param name="lParam">The second Windows Message parameter.</param>
        /// <returns>A new KeyPressEventArgsExt object.</returns>
        internal static KeyPressEventArgsExt FromRawDataGlobal( int wParam, IntPtr lParam )
        {
            if ( wParam != Messages.WM_KEYDOWN )
            {
                return new KeyPressEventArgsExt( ( char )0 );
            }

            KeyboardHookStruct keyboardHookStruct = ( KeyboardHookStruct )Marshal.PtrToStructure( lParam, typeof( KeyboardHookStruct ) );

            int virtualKeyCode = keyboardHookStruct.VirtualKeyCode;
            int scanCode = keyboardHookStruct.ScanCode;
            int fuState = keyboardHookStruct.Flags;

            char ch;

            if ( virtualKeyCode == KeyboardNativeMethods.VK_PACKET )
            {
                ch = ( char )scanCode;
            }
            else
            {
                bool isSuccessfull = KeyboardNativeMethods.TryGetCharFromKeyboardState( virtualKeyCode, scanCode, fuState, out ch );
                if ( !isSuccessfull )
                {
                    return new KeyPressEventArgsExt( ( char )0 );
                }
            }

            KeyPressEventArgsExt e = new KeyPressEventArgsExt( ch, keyboardHookStruct.Time );
            return e;
        }
 private void InvokeKeyPress(int wParam, IntPtr lParam)
 {
     InvokeKeyPress(KeyPressEventArgsExt.FromRawData(wParam, lParam, IsGlobal));
 }