Inheritance: System.EventArgs
Beispiel #1
0
        /// <summary>
        /// Main HookProc: chain the call if not canceled by <see cref="HookProcInvoked"/>.
        /// </summary>
        private int MainHookProc( int code, IntPtr wParam, IntPtr lParam )
        {
            //Debug.WriteLine( "HookProcInvoked " );
            if( code < 0 ) return Win32Wrapper.CallNextHookEx( _hookHandle, code, wParam, lParam );

            HookEventArgs e = new HookEventArgs(code, wParam, lParam);
            if( HookProcInvoked != null ) HookProcInvoked( this, e );
            if( e.Cancel ) return CANCEL_VALUE;
            return Win32Wrapper.CallNextHookEx( _hookHandle, code, wParam, lParam );
        }
Beispiel #2
0
        /// <summary>
        /// Method which provides an interpretation for all hook events.
        /// Depending of the hook's params we'll fire the good event.
        /// </summary>
        private void OnHookInvoqued( object sender, HookEventArgs e )
        {
            if( e.Code >= 0 && e.wParam == (IntPtr)WM_KEYDOWN )
            {

                LLKBDHOOKSTRUCT keyboardInfo = (LLKBDHOOKSTRUCT)Marshal.PtrToStructure( e.lParam, typeof( LLKBDHOOKSTRUCT ) );
                int vkCode = keyboardInfo.wVk;
                if( _cancellableKeys.Contains( vkCode ) || _cancellableKeys.Contains( -1 ) )
                {

                    InputSource source = InputSource.Other;
                    if( (int)keyboardInfo.dwExtraInfo == 39229115 ) //CiviKey's footprint
                    {
                        source = InputSource.CiviKey;
                    }
                    else
                    {
                        //We only swallow the event if we are going to do something with it and that it does not come from CiviKey
                        if( KeyDown != null ) e.Cancel = true;
                    }

                    Dispatcher.CurrentDispatcher.BeginInvoke( (Action<int, InputSource>)FireEvent, vkCode, source );
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Simulate a ButtonDown Event
        /// </summary>
        /// <param name="buttonInfo">Default button is Left, look at ButtonInfo to see available buttons</param>
        //public void SimulateButtonDown( ButtonInfo buttonInfo, string extraInfo )
        //{
        //    if( buttonInfo == ButtonInfo.DefaultButton )
        //        Win32Wrapper.mouse_event( MouseEventFlags.LEFTDOWN, 0, 0, 0, 0 );
        //    if( buttonInfo == ButtonInfo.XButton && extraInfo == ButtonExtraInfo.Right )
        //        Win32Wrapper.mouse_event( MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0 );
        //    if( buttonInfo == ButtonInfo.XButton && extraInfo == ButtonExtraInfo.Middle )
        //        Win32Wrapper.mouse_event( MouseEventFlags.MIDDLEDOWN, 0, 0, 0, 0 );
        //}
        /// <summary>
        /// Simulate a ButtonUp Event
        /// </summary>
        /// <param name="buttonInfo">Default button is Left, look at ButtonInfo to see available buttons</param>
        //public void SimulateButtonUp( ButtonInfo buttonInfo, string extraInfo )
        //{
        //    if( buttonInfo == ButtonInfo.DefaultButton )
        //        Win32Wrapper.mouse_event( MouseEventFlags.LEFTUP, 0, 0, 0, 0 );
        //    if( buttonInfo == ButtonInfo.XButton && extraInfo == ButtonExtraInfo.Right )
        //        Win32Wrapper.mouse_event( MouseEventFlags.RIGHTUP, 0, 0, 0, 0 );
        //    if( buttonInfo == ButtonInfo.XButton && extraInfo == ButtonExtraInfo.Middle )
        //        Win32Wrapper.mouse_event( MouseEventFlags.MIDDLEUP, 0, 0, 0, 0 );
        //}
        /// <summary>
        /// Method which provides an interpretation for all hook events.
        /// Depending of the hook's params we'll fire the good event.
        /// </summary>
        private void OnHookInvoqued( object sender, HookEventArgs e )
        {
            MouseMessage mouseMessage = (MouseMessage)e.wParam.ToInt32();
            //If this is a mouse move and the pointerPosGetter is set, return, the hook should not process it.
            if( _pointerPosGetter != null && mouseMessage == MouseMessage.WM_MOUSEMOVE ) return;

            LLMouseHookStruct mouseInfo = (LLMouseHookStruct)Marshal.PtrToStructure( e.lParam, typeof( LLMouseHookStruct ) );
            MouseHookAction action = (MouseHookAction)e.Code;

            InputSource source = InputSource.Other;
            if( (int)mouseInfo.dwExtraInfo == 39229115 ) //CiviKey's footprint
            {
                source = InputSource.CiviKey;
            }

            // We only handle the hook if the hook proc contain informations
            if( action == MouseHookAction.HC_ACTION )
            {
                _lastPointerPosition.X = mouseInfo.pt.X;
                _lastPointerPosition.Y = mouseInfo.pt.Y;
                string buttonExtraInfo = String.Empty;
                ButtonInfo buttonInfo = GetButtonInfo( mouseMessage, out buttonExtraInfo );

                PointerDeviceEventArgs pointerEventArgs = new PointerDeviceEventArgs( _lastPointerPosition.X, _lastPointerPosition.Y, buttonInfo, buttonExtraInfo, source );

                // We look at the MouseMessage (wParam of the HookProc delegate) to know which event to fire.
                if( mouseMessage == MouseMessage.WM_MOUSEMOVE && InternalPointerMove != null )
                {
                    InternalPointerMove( this, pointerEventArgs );
                }
                else if( mouseMessage == MouseMessage.WM_LBUTTONDOWN ||
                    mouseMessage == MouseMessage.WM_MBUTTONDOWN ||
                    mouseMessage == MouseMessage.WM_RBUTTONDOWN )
                {
                    if( PointerButtonDown != null ) PointerButtonDown( this, pointerEventArgs );
                }
                else if( mouseMessage == MouseMessage.WM_LBUTTONUP ||
                    mouseMessage == MouseMessage.WM_MBUTTONUP ||
                    mouseMessage == MouseMessage.WM_RBUTTONUP )
                {
                    if( PointerButtonUp != null ) PointerButtonUp( this, pointerEventArgs );
                }

                // if a client wanted to cancel the current event we tell it to the WindowsHook procedure.
                if( pointerEventArgs.Cancel )
                    e.Cancel = true;
            }
        }