예제 #1
0
        private void PreProcessInput(object sender, PreProcessInputEventArgs e)
        {
            InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;

            if (input != null)
            {
                if (input.Report.Type == InputType.Command)
                {
                    RawAppCommandInputReport rawAppCommandInputReport = input.Report as RawAppCommandInputReport;
                    if (rawAppCommandInputReport != null)
                    {
                        // Claim the input for the Command.
                        input.Device = this;

                        // Set the proper source
                        input.Source = GetSourceFromDevice(rawAppCommandInputReport.Device);
                    }
                }
            }
        }
예제 #2
0
 private void PostProcessInput(object sender, ProcessInputEventArgs e)
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         if (!e.StagingItem.Input.Handled)
         {
             InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;
             if (inputReportEventArgs != null)
             {
                 RawAppCommandInputReport rawAppCommandInputReport = inputReportEventArgs.Report as RawAppCommandInputReport;
                 if (rawAppCommandInputReport != null)
                 {
                     IInputElement commandTarget = e.StagingItem.Input.OriginalSource as IInputElement;
                     if (commandTarget != null)
                     {
                         RoutedCommand command = GetRoutedCommand(rawAppCommandInputReport.AppCommand);
                         if (command != null)
                         {
                             // Send the app command to the tree to be handled by UIElements and ContentElements
                             // that will forward the event to CommandManager.
                             CommandDeviceEventArgs args = new CommandDeviceEventArgs(this, rawAppCommandInputReport.Timestamp, command);
                             args.RoutedEvent = CommandDeviceEvent;
                             args.Source      = commandTarget;
                             e.PushInput(args, e.StagingItem);
                         }
                     }
                 }
             }
         }
     }
     else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent ||
              e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.GotKeyboardFocusEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.LostKeyboardFocusEvent)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }
예제 #3
0
        internal IntPtr FilterMessage( IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool handled )
        {
            // It is possible to be re-entered during disposal.  Just return.
            if(null == _source || null == _source.Value)
            {
                return IntPtr.Zero;
            }
            
            if (msg == WindowMessage.WM_APPCOMMAND)
            {
                // WM_APPCOMMAND message notifies a window that the user generated an application command event,
                // for example, by clicking an application command button using the mouse or typing an application command
                // key on the keyboard.
                RawAppCommandInputReport report = new RawAppCommandInputReport(
                                                        _source.Value,
                                                        InputMode.Foreground,
                                                        SafeNativeMethods.GetMessageTime(),
                                                        GetAppCommand(lParam),
                                                        GetDevice(lParam),
                                                        InputType.Command);

                handled = _site.Value.ReportInput(report);
            }
            
            return handled ? new IntPtr(1) : IntPtr.Zero ;
        }