Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

c# - How to get graphic tablet pen pressure value?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...