text: Q:
  
  WF4 Rehosted - get delete key pressed before ModelChanged is triggered
  
  I am trying to keep track of what activities are selected in the workflow and make some checks before deleting them. 
    wd.Context.Items.Subscribe<Selection>(SelectionChanged);
  
      List<ModelItem> selectedModelItems = new List<ModelItem>();
      private void SelectionChanged(Selection selection)
      {
          selectedModelItems.Clear();
          foreach (ModelItem mi in selection.SelectedObjects)
          {
              selectedModelItems.Add(mi);
          }
      }
  
  While pressing CTRL and selecting my items all goes well, the selectedModelItems list is populated correctly. 
  But the deletion moment arrives and before the trigger of the ModelChanged event, this SelectionChanged handler comes in action and resets all my selections because, in fact now, beeing deleted, they are not selected anymore. What i am looking for is a way to get access to that delete key pressed before the selection changes, and this way save that list to another buffer before it gets cleared. 
  The unloaded event of my custom activities comes after the ModelChanged so that's not an option. 
  UPDATE: 
  I made new step forward:
      protected override void OnKeyDown(KeyEventArgs e)
      {
          if (e.Key == Key.Delete)
          {
              Console.WriteLine("test");
          }
          base.OnKeyDown(e);
      }
  
  but this handler doesn't catch my delete key pressed. Some other keys like ctrl, or letters, are working fine and the event fires. Any idea about this ?
  
  A:
  
  OK, found the thing : OnPreviewKeyDown event.   
      List<ModelItem> selectedModelItems = new List<ModelItem>();
      protected override void OnPreviewKeyDown(KeyEventArgs e)
      {
          if (e.Key == Key.Delete)
          {
              IEnumerable<ModelItem> activities = wd.Context.Items.GetValue<Selection>().SelectedObjects;
              foreach (ModelItem mi in activities)
              {
                  selectedModelItems.Add(mi);
              }
  
          }
          base.OnPreviewKeyDown(e);
      }
  
  That's it, i am able to get the selected items, when pressing the delete key, and before the selection goes away.
  
  