I am using RealTimeStylus to get Ink data in a WPF application. This works fine until the window on which I collect the ink loses focus. When I draw on the window after that, the AsyncStylusPlugin does not receive Packets, StylusUp or StylusDown events, even if it get the focus again.
The curious thing is that this problem only occurs on my Tablet PC where I am using the stylus, not on my desktop PC where I am using a mouse. Also an equivalent application that uses System.Windows.Forms instead of WPF does not suffer from this problem.
A minimal example that shows the problem is given below. Any ideas what might be causing this issue?
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Interop;
using Microsoft.StylusInput;
namespace MinimalExample
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Window1_Loaded);
}
void Window1_Loaded(object sender, RoutedEventArgs e)
{
IntPtr ptr = new WindowInteropHelper(this).Handle;
RealTimeStylus rts = new RealTimeStylus(ptr);
AsyncStylusPlugin plugin = new AsyncStylusPlugin();
rts.AsyncPluginCollection.Add(plugin);
rts.Enabled = true;
}
}
}
And now the AsyncStylusPlugin:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.StylusInput;
using Microsoft.StylusInput.PluginData;
namespace MinimalExample
{
class AsyncStylusPlugin : IStylusAsyncPlugin
{
public DataInterestMask DataInterest
{
get
{
return DataInterestMask.Packets | DataInterestMask.StylusDown | DataInterestMask.StylusUp;
}
}
public AsyncStylusPlugin()
{
}
public void Packets(RealTimeStylus sender, PacketsData data)
{
for (int i = 0; i < data.Count; i += data.PacketPropertyCount)
{
Console.WriteLine("Packet: X " + data[i].ToString() + " / Y " + data[i + 1].ToString());
}
}
public void StylusDown(RealTimeStylus sender, StylusDownData data)
{
Console.WriteLine("StylusDown");
}
public void StylusUp(RealTimeStylus sender, StylusUpData data)
{
Console.WriteLine("StylusUp");
}
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)
{
}
}
}