5

I'm using a Wacom Bamboo Pen tablet and I'd like to be able to get its pen pressure value in my application written in C#. How do I do that? Is there maybe an API that allows one to get pen values on Windows 7?

Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
user1306322
  • 8,561
  • 18
  • 61
  • 122
  • Can someone add `graphics-tablet` tag to this question? – user1306322 Jun 29 '13 at 18:05
  • 1
    Are you using WPF? In WPF's MouseEventArgs, there is a StylusDevice properties that can get a collection of StylusPoint. Eeach point has a PressureFactor property. – Simon Mourier Aug 02 '13 at 16:50
  • @SimonMourier I can't find it anywhere. It seems it's in `System.Windows.Input` namespace, but I don't see a reference to it in default set of components. Am I missing some software package? – user1306322 Aug 02 '13 at 17:36
  • It should be in PresentationCore.dll: http://msdn.microsoft.com/library/system.windows.input.stylusdevice.aspx – Simon Mourier Aug 03 '13 at 07:17
  • I tried using this in a WinForms app and the usual OnMouseMove handler doesn't seem to have an overload that uses PresentationCore's mouse info. I'm not sure how to make this work in a non-wpf app. – user1306322 Aug 04 '13 at 01:59
  • You can't. That's why I was asking about WPF. – Simon Mourier Aug 04 '13 at 06:24

2 Answers2

15

Wacom provides an extensive API to get data directly from the tablet.The API includes example code for detecting pressure, tilt and other interactions:

  • Tilt Test: Demonstrates pressure, use of the eraser and pen tilt properties
  • Pressure Test: Demonstrates how to detect and display pen pressure

These code samples are in C, but there are also examples that in c#.net that include code to handle pressure:

  • WintabDN: Interface, scribble and tablet control samples using Wintab .NET

Using this project as an example, you can get the pressure like this:

// Create a data object and hook a packetlistener to receive
// updatse by the tablet
m_wtData = new CWintabData();
m_wtData.SetWTPacketEventHandler(handler);

//Handles packet receive event
void handler(object sender,MessageReceivedEventArgs e)
{
     //Get the packet id
     uint pktID = (uint)eventArgs_I.Message.WParam;

     //Get the data for that packet
     WintabPacket pkt = m_wtData.GetDataPacket((uint)eventArgs_I.Message.LParam, pktID);

     //Grab the pressure
     var pressure = pk.pkNormalPressure.pkAbsoluteNormalPressure;
}

Next, here is a CodeProject that explains how to use the Wacom Tablet with the WPF InkCanvas

A good starting point for any tablet related development on windows is also the Ink API.

dsfgsho
  • 2,731
  • 2
  • 22
  • 39
1

Can be a starting point

http://www.codeproject.com/Articles/46281/Digitizer-interface-in-C-using-VBTablet

Thats the right link to the project: http://sourceforge.net/projects/vbtablet/

Diego C Nascimento
  • 2,801
  • 1
  • 17
  • 23