fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.Windows.Input;
  7.  
  8. namespace Livet
  9. {
  10. public static class LivetCommandManager
  11. {
  12. static LivetCommandManager()
  13. {
  14. InputManager.Current.PostProcessInput += new ProcessInputEventHandler(RaisedPostProcessInput);
  15.  
  16. var primaryCommandDevice = typeof(InputManager)
  17. .GetProperty("PrimaryCommandDevice", BindingFlags.Instance | BindingFlags.NonPublic)
  18. .GetValue(InputManager.Current, null);
  19.  
  20. var preProcessInput = primaryCommandDevice.GetType()
  21. .GetMethod("PreProcessInput", BindingFlags.Instance | BindingFlags.NonPublic);
  22.  
  23. var postProcessInput = primaryCommandDevice.GetType()
  24. .GetMethod("PostProcessInput", BindingFlags.Instance | BindingFlags.NonPublic);
  25.  
  26. var preProcessInputDelegate = Delegate.CreateDelegate(typeof(PreProcessInputEventHandler), primaryCommandDevice, preProcessInput);
  27. var postProcessInputDelegate = Delegate.CreateDelegate(typeof(ProcessInputEventHandler), primaryCommandDevice, postProcessInput);
  28.  
  29. typeof(InputManager).GetEvent("PreProcessInput").RemoveEventHandler(InputManager.Current, preProcessInputDelegate);
  30. typeof(InputManager).GetEvent("PostProcessInput").RemoveEventHandler(InputManager.Current, postProcessInputDelegate);
  31.  
  32. Mode = InvalidateRequerySuggestedMode.Default;
  33. }
  34.  
  35. private static void RaisedPostProcessInput(object sender, ProcessInputEventArgs e)
  36. {
  37. if (Mode == InvalidateRequerySuggestedMode.Default || Mode == InvalidateRequerySuggestedMode.Full)
  38. {
  39. var routedEvent = e.StagingItem.Input.RoutedEvent;
  40.  
  41. if (routedEvent == Keyboard.KeyUpEvent ||
  42. routedEvent == Mouse.MouseUpEvent ||
  43. routedEvent == Keyboard.GotKeyboardFocusEvent ||
  44. routedEvent == Keyboard.LostKeyboardFocusEvent)
  45. {
  46. CommandManager.InvalidateRequerySuggested();
  47. }
  48. }
  49. }
  50.  
  51. public static InvalidateRequerySuggestedMode Mode
  52. {
  53. get;
  54. set;
  55. }
  56. }
  57.  
  58. public enum InvalidateRequerySuggestedMode
  59. {
  60. None,
  61. Default,
  62. Full
  63. }
  64. }
  65.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty