IStylusSyncPlugin not receiving data after windows loses focus

188 views Asked by At

I am using IStylusSyncPlugin added to RealTimeStylus plugins to get X,Y,Pressure and timer tick from stylus. This works fine until the window on which I collect this data loses focus. After that, even if focus get back to window, the StylusSyncPlugin does not receiving data. Do anyone have any idea what can i do, to fix this problem? I've found, that stylus events from main window (for ex. PreviewStylusMove) are still firing, but points from these events does not contains timestamp. A simple code example which could be helpful to reproduce this issue:

 public partial class MainWindow : Window
 {
     public MainWindow()
     {
         InitializeComponent();
         this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
     }
     void MainWindow_Loaded(object sender, RoutedEventArgs e)
     {
         RealTimeStylus rts = new RealTimeStylus(new WindowInteropHelper(this).Handle);
         rts.AsyncPluginCollection.Add(new SyncStylusPlugin());
         rts.Enabled = true;
     }
     class SyncStylusPlugin : IStylusSyncPlugin
     {
         public DataInterestMask DataInterest => DataInterestMask.Packets;
         public void Packets(RealTimeStylus sender, PacketsData data)
         {
             Console.WriteLine("Packets arrived");
         }
         public void StylusDown(RealTimeStylus sender, StylusDownData data) { }
         public void StylusUp(RealTimeStylus sender, StylusUpData data) { }
         public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data) { }
         public void Error(RealTimeStylus sender, ErrorData data) { }
         public void InAirPackets(RealTimeStylus sender, InAirPacketsData data) { }
         public void RealTimeStylusDisabled(RealTimeStylus sender, RealTimeStylusDisabledData data) { }
         public void RealTimeStylusEnabled(RealTimeStylus sender, RealTimeStylusEnabledData data) { }
         public void StylusButtonDown(RealTimeStylus sender, StylusButtonDownData data) { }
         public void StylusButtonUp(RealTimeStylus sender, StylusButtonUpData data) { }
         public void StylusInRange(RealTimeStylus sender, StylusInRangeData data) { }
         public void StylusOutOfRange(RealTimeStylus sender, StylusOutOfRangeData data) { }
         public void SystemGesture(RealTimeStylus sender, SystemGestureData data) { }
         public void TabletAdded(RealTimeStylus sender, TabletAddedData data) { }
         public void TabletRemoved(RealTimeStylus sender, TabletRemovedData data) { }
     }
 }

I've found, that click on application icon at taskbar making RealTimeStylus work again. Is there any way to fire the same events like mouse do when clicking on this icon? Which events should be fired?

EDIT:

During reading microsoft docs about RealTimeStylus I've found, that "When you create a RealTimeStylus object, you have the option of attaching it to a window handle or to a control. Attaching the RealTimeStylus object to a window handle requires additional permissions. For more information about these permissions, see Partial Trust Considerations for the StylusInput APIs." "The RealTimeStylus that takes the handle parameter requires the UIPermissionWindow.AllWindows and SecurityPermissionFlag.UnmanagedCode permissions, in addition to the permissions required by the constructor that takes the attachedControl parameter." Do anyone know how to check, if Window has these permissions, and how to track them to check if Window loses them sometimes on focus lost?

EDIT2: I tried to set UIPermission by adding [UIPermission(SecurityAction.Demand, Window =UIPermissionWindow.AllWindows)] to main window class and also by setting new UIPermission(UIPermissionWindow.AllWindows).Demand(); in main window constructor, but it changes nothing.

EDIT3: Next thing that I have noticed is that, the StylusInRange and StylusOutOfRange events are working everytime, even if window has no focus.

0

There are 0 answers