Provides extended data for the event.
상속: System.Windows.Forms.KeyPressEventArgs
예제 #1
0
 private static KeyPressEventArgsExt CreateNonChar()
 {
     KeyPressEventArgsExt e = new KeyPressEventArgsExt((char)0x0);
     e.IsNonChar = true;
     e.Timestamp = Environment.TickCount;
     return e;
 }
예제 #2
0
 private void InvokeKeyPress(KeyPressEventArgsExt e)
 {
     KeyPressEventHandler handler = KeyPress;
     if (handler == null || e.Handled || e.IsNonChar) { return; }
     handler(this, e);
 }
예제 #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));
 }