Browse DevX
Sign up for e-mail newsletters from DevX


Get Control and Performance with the Real Time Stylus API : Page 2

The Real Time Stylus API provides an alternate way to receive pen input pen. This high performance API provides a great level of control to developers for a small penalty in added effort.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Adding a Form
Now that you have a simple plug-in ready to go, all you need is something to attach it to. In a very simple version, this could be a form. When that form instantiates, create a RealTimeStylus object and point it to the UI control you want to collect pen information on (in this example the entire window, but it could be an individual control, such as a textbox or a panel). Then, instantiate the plug-in object and add it to the Real Time Stylus' SyncPluginCollection. The following snippet shows how this can be done in VB.NET:

Private rts As RealTimeStylus Public Sub New() MyBase.New() 'This call is req. by the Win Form Designer. InitializeComponent() 'We create the stylus Me.rts = New RealTimeStylus(Me) Dim plugIn As New SimpleStylus Me.rts.SyncPluginCollection.Add(plugIn) Me.rts.Enabled = True End Sub

Here is the C# version:

private RealTimeStylus rts; public SimpleStylusForm() { InitializeComponent(); // We create the stylus this.rts = new RealTimeStylus(this); SimpleStylus plugIn = new SimpleStylus(); this.rts.SyncPluginCollection.Add(plugIn); this.rts.Enabled = true; }

Listing 3 and Listing 4 show the complete form code for both VB and C# versions, respectively.

The Real Time Stylus API can be used to filter and manipulate pen input before it gets processed or recognized.
You can now run this application and watch the output window to see stylus events being handled by the new real-time plug-in. The output you see might look similar to the following:

Stylus Down Packet: X 5133/ Y 4207 Packet: X 5133/ Y 4180 ... Packet: X 4577/ Y 3731 Packet: X 4577/ Y 3757 Stylus Up

Expect to see a lot of Packet lines, as those events fire very fast and very often during typical drawing operations.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date