internal TabletDevice(TabletDeviceInfo tabletInfo, PenThread penThread) { _tabletInfo = tabletInfo; _penThread = penThread; int count = tabletInfo.StylusDevicesInfo.Length; StylusDevice[] styluses = new StylusDevice[count]; for ( int i = 0; i < count; i++ ) { StylusDeviceInfo cursorInfo = tabletInfo.StylusDevicesInfo[i]; styluses[i] = new StylusDevice( this, cursorInfo.CursorName, cursorInfo.CursorId, cursorInfo.CursorInverted, cursorInfo.ButtonCollection); } _stylusDeviceCollection = new StylusDeviceCollection(styluses); if (_tabletInfo.DeviceType == TabletDeviceType.Touch) { // _multiTouchSystemGestureLogic = new MultiTouchSystemGestureLogic(); } }
public static string ToText(this StylusDeviceCollection ds) { StringBuilder sb = new StringBuilder(); foreach (StylusDevice d in ds) { sb.Append(" Id: " + d.Id.ToString() + " Position: " + d.GetPosition(d.Target).ToText() + " InAir: " + d.InAir.ToString() + " InRange: " + d.InRange.ToString() + " Inverted: " + d.Inverted.ToString() + " Name: " + d.Name + " Buttons: " + d.StylusButtons.ToText()); } return(sb.ToString()); }
private void BuildStylusDevices() { UInt32 cursorCount = 0; List <PointerStylusDevice> pointerStylusDevices = new List <PointerStylusDevice>(); if (UnsafeNativeMethods.GetPointerDeviceCursors(_deviceInfo.Device, ref cursorCount, null)) { UnsafeNativeMethods.POINTER_DEVICE_CURSOR_INFO[] cursors = new UnsafeNativeMethods.POINTER_DEVICE_CURSOR_INFO[cursorCount]; if (UnsafeNativeMethods.GetPointerDeviceCursors(_deviceInfo.Device, ref cursorCount, cursors)) { foreach (var cursor in cursors) { PointerStylusDevice stylus = new PointerStylusDevice(this, cursor); _stylusDeviceMap.Add(stylus.CursorId, stylus); pointerStylusDevices.Add(stylus); } } } _stylusDevices = new StylusDeviceCollection(pointerStylusDevices.ToArray()); }
// When user clicks button, // Display capabilities to panel private void Button1Click(object sender, RoutedEventArgs e) { // Clear the textbox if they clicked once before textbox1.Clear(); // <Snippet1> // Get the current stylus device StylusDevice myStylusDevice = Stylus.CurrentStylusDevice; // </Snippet1> // Check whether we got the current stylus if (null == myStylusDevice) { textbox1.AppendText("No current stylus device\n"); // Try to get it through the default tablet TabletDevice defaultTabletDevice = Tablet.TabletDevices[0]; // Quit if we did not get the default tablet if (null == defaultTabletDevice) { textbox1.AppendText("No default tablet device. Goodby!\n"); return; } // Now try to get the default stylus device through the default tablet device StylusDeviceCollection myStylusDeviceCollection = defaultTabletDevice.StylusDevices; int numStylusDevices = myStylusDeviceCollection.Count; // If none returned, we are toast, so quit if (numStylusDevices < 1) { textbox1.AppendText("No stylus devices attached.\n"); return; } else { // We have at least one stylus device, so just grab the first one textbox1.AppendText("Got " + numStylusDevices + " stylus device through default tablet\n"); myStylusDevice = myStylusDeviceCollection[0]; } } // See what properties the default stylus device has // <Snippet2> PresentationSource myPresentationSource = myStylusDevice.ActiveSource; if (null == myPresentationSource) { textbox1.AppendText("ActiveSource : null\n"); } else { textbox1.AppendText("ActiveSource :" + myPresentationSource.ToString() + "\n"); } // </Snippet2> // <Snippet15> TabletDevice myTabletDevice = myStylusDevice.TabletDevice; // </Snippet15> // <Snippet3> // Bind stylus to tablet's input element myStylusDevice.Capture(myStylusDevice.Target); // </Snippet3> // <Snippet4> // See to what Captured property is set // First see if it's null if (null == myStylusDevice.Captured) { textbox1.AppendText("Captured: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("Captured: " + myStylusDevice.Captured.GetType().Name + "\n"); } // </Snippet4> // <Snippet5> // Bind stylus to tablet's input element // through entire subtree myStylusDevice.Capture(myStylusDevice.Target, CaptureMode.SubTree); // </Snippet5> // <Snippet6> // See to what DirectlyOver property is set // First see if it's null if (null == myStylusDevice.DirectlyOver) { textbox1.AppendText("DirectlyOver: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("DirectlyOver: " + myStylusDevice.DirectlyOver.GetType().Name + "\n"); } // </Snippet6> //StylusPointDescription // <Snippet7> StylusPointCollection myStylusPoints = myStylusDevice.GetStylusPoints(myStylusDevice.Target); textbox1.AppendText("Got " + myStylusPoints.Count.ToString() + " packets\n"); // </Snippet7> // <Snippet8> Point myPoint = myStylusDevice.GetPosition(myStylusDevice.Target); textbox1.AppendText("The relative position is: (" + myPoint.X.ToString() + "," + myPoint.Y.ToString() + ")\n"); // </Snippet8> // <Snippet9> textbox1.AppendText("Id: " + myStylusDevice.Id.ToString() + "\n"); // </Snippet9> // <Snippet11> textbox1.AppendText("InRange: " + myStylusDevice.InRange.ToString() + "\n"); // </Snippet11> // <Snippet13> textbox1.AppendText("Name: " + myStylusDevice.Name + "\n"); // </Snippet13> // <Snippet14> StylusButtonCollection myStylusButtonCollection = myStylusDevice.StylusButtons; if (null == myStylusButtonCollection) { textbox1.AppendText("StylusButtons: null\n"); } else { textbox1.AppendText("# of StylusButtons == " + myStylusButtonCollection.Count.ToString() + "\n"); } // </Snippet14> // Snippet 15 (TabletDevice property) is between snippet 2 and snippet 3 // <Snippet16> // See to what Target property is set // First see if it's null if (null == myStylusDevice.Target) { textbox1.AppendText("Target: null\n"); } else { // Otherwise display the underlying type textbox1.AppendText("Target: " + myStylusDevice.Target.GetType().Name + "\n"); } // </Snippet16> // <Snippet17> textbox1.AppendText("\n" + "StylusDevice: " + myStylusDevice.ToString() + "\n"); // </Snippet17> // StylusButton members // Dummy array to hold result of CopyTo method StylusButton[] myStylusButtonArray = new StylusButton[100]; int index = 0; // <Snippet19> myStylusButtonCollection.CopyTo(myStylusButtonArray, index); // </Snippet19> // <Snippet20> // Get the names of the buttons for (int i = 0; i < myStylusButtonCollection.Count; i++) { textbox1.AppendText("Button[" + i + "]: " + myStylusButtonCollection[i].Name); } // </Snippet20> // <Snippet21> // Ensure collection access is synchronized //if (!myStylusButtonCollection.IsSynchronized) //{ // lock (myStylusButtonCollection.SyncRoot) // { // // work with collection // } //} // </Snippet21> // <Snippet22> // Get the names of all of the of StylusButton objects // and store them in an ArrayList ArrayList myStylusButtonNamesArrayList = new ArrayList(); foreach (StylusButton sb in myStylusButtonCollection) { myStylusButtonNamesArrayList.Add(sb.Name); } // </Snippet22> // <Snippet23> // Get the first StylusButton, if it exists if (myStylusButtonCollection.Count > 0) { StylusButton mySB = myStylusButtonCollection[0]; } // </Snippet23> StylusButton myStylusButton = myStylusButtonCollection[0]; // <Snippet25> // Get the name of the StylusButton textbox1.AppendText("StylusButton.Name: " + myStylusButton.Name + "\n"); // </Snippet25> // <Snippet26> // Get the state of the StylusButton switch (myStylusButton.StylusButtonState) { case StylusButtonState.Down: textbox1.AppendText("StylusButton.State: Down\n"); break; default: // StylusButtonState.Up textbox1.AppendText("StylusButton.State: Up\n"); break; } // </Snippet26> // <Snippet27> // Get the name of the StylusDevice to which the StylusButton is attached textbox1.AppendText("StylusButton.StylusDevice: " + myStylusButton.StylusDevice.Name + "\n"); // </Snippet27> // <Snippet28> // Get string representation of the StylusButton textbox1.AppendText("\n" + myStylusButton.ToString() + "\n"); // </Snippet28> }
// To use Loaded event put Loaded="WindowLoaded" attribute in root element of .xaml file. // private void WindowLoaded(object sender, EventArgs e) {} // When user clicks button, display capabilities in panel private void Button1Click(object sender, RoutedEventArgs e) { // Clear the textbox if they clicked once before textbox1.Clear(); // Find out if we have more than one tablet device int count = Tablet.TabletDevices.Count; if (count == 1) { textbox1.AppendText("There is one tablet device\n"); } else { textbox1.AppendText("There are " + count + " tablet devices\n"); } // <Snippet7> // Get the current tablet device, if it exists TabletDevice myCurrentTabletDevice = Tablet.CurrentTabletDevice; // </Snippet7> if (null != myCurrentTabletDevice) { textbox1.AppendText("INFO: Got the current tablet device\n"); } else { textbox1.AppendText("INFO: Cannot get the current tablet device\n"); } // <Snippet15> // Get the TabletDevice objects TabletDeviceCollection myTabletDeviceCollection = Tablet.TabletDevices; // <Snippet24> // Display the types of TabletDevices foreach (TabletDevice td in myTabletDeviceCollection) { Console.WriteLine(td.Type); } // </Snippet24> // </Snippet15> // Store them in an array of strings // <Snippet16> // Get the number of tablet devices int numTabletDevices = myTabletDeviceCollection.Count; // </Snippet16> // <Snippet19> string[] myTabletDeviceNamesArray = new string[numTabletDevices]; for (int i = 0; i < numTabletDevices; i++) { myTabletDeviceNamesArray[i] = myTabletDeviceCollection[i].Name; } // </Snippet19> bool gotCurrentTabletDevice = false; // Display a list of tablet device names for (int i = 0; i < numTabletDevices; i++) { TabletDevice theTD = myTabletDeviceCollection[i]; textbox1.AppendText("TabletDevice[" + i + "].Name == \"" + theTD.Name + "\""); // Is this one the current TabletDevice? if (theTD == myCurrentTabletDevice) { textbox1.AppendText(" (current tablet device)\n\n"); gotCurrentTabletDevice = true; } else { textbox1.AppendText("\n\n"); } } if (!gotCurrentTabletDevice) { textbox1.AppendText("No match for current tablet device\n\n"); } // <Snippet17> // Is the collection thread safe? if (!myTabletDeviceCollection.IsSynchronized) { // If not, use SyncRoot to lock access lock (myTabletDeviceCollection.SyncRoot) { // work with collection } } // </Snippet17> TabletDevice[] myTabletDeviceArray = new TabletDevice[100]; int index = 0; // <Snippet18> // Copy the collection to array of tablet devices starting at position index myTabletDeviceCollection.CopyTo(myTabletDeviceArray, index); // </Snippet18> // <Snippet3> // Get the first tablet device TabletDevice myTabletDevice = Tablet.TabletDevices[0]; // </Snippet3> // If tablet device exists, display its capabilities if (null != myTabletDevice) { textbox1.AppendText("TABLET\n\n"); textbox1.AppendText("Properties\n\n"); // Display the tablet device properties // <Snippet4> PresentationSource myPresentationSource = myTabletDevice.ActiveSource; if (null != myPresentationSource) { textbox1.AppendText("ActiveSource.RootVisual: " + myPresentationSource.RootVisual.ToString() + "\n"); } else { textbox1.AppendText("ActiveSource: null\n"); } // </Snippet4> // <Snippet5> System.Windows.Threading.Dispatcher myDispatcher = myTabletDevice.Dispatcher; if (null != myDispatcher) { textbox1.AppendText("Dispatcher: " + myDispatcher.ToString() + "\n"); } else { textbox1.AppendText("Dispatcher: null\n"); } // </Snippet5> // <Snippet8> textbox1.AppendText("Id: " + myTabletDevice.Id + "\n"); // </Snippet8> // <Snippet9> textbox1.AppendText("Name: " + myTabletDevice.Name + "\n"); // </Snippet9> // <Snippet10> textbox1.AppendText("ProductId: " + myTabletDevice.ProductId + "\n"); // </Snippet10> // <Snippet11> // Get the StylusDevice objects. StylusDeviceCollection myStylusDeviceCollection = myTabletDevice.StylusDevices; // Get the names of all of the of StylusDevice objects. string[] myStylusDeviceNames = new string[myStylusDeviceCollection.Count]; for (int i = 0; i < myStylusDeviceCollection.Count; i++) { myStylusDeviceNames[i] = myStylusDeviceCollection[i].Name; } // </Snippet11> // Or store them in an array of strings // <Snippet20> // Get the number of stylus devices int numStylusDevices = myStylusDeviceCollection.Count; // </Snippet20> // <Snippet21> string[] myStylusDeviceNamesArray = new string[numStylusDevices]; for (int i = 0; i < numStylusDevices; i++) { myStylusDeviceNamesArray[i] = myStylusDeviceCollection[i].Name; } // </Snippet21> // <Snippet22> // Is the collection thread safe? //if (!myStylusDeviceCollection.IsSynchronized) //{ // // If not, use SyncRoot to lock access // lock (myStylusDeviceCollection.SyncRoot) // { // // work with collection // } //} // </Snippet22> StylusDevice[] myStylusDeviceArray = new StylusDevice[100]; index = 0; // <Snippet23> // Copy the collection to array of stylus devices starting at position index myStylusDeviceCollection.CopyTo(myStylusDeviceArray, index); // </Snippet23> for (int i = 0; i < myStylusDeviceCollection.Count; i++) { textbox1.AppendText("StylusDevice[" + i + "] name: " + myStylusDeviceCollection[i].Name + "\n"); } // <Snippet12> //StylusPointDescription myStylusPointDescription = myTabletDevice.StylusPacketDescription; // </Snippet12> //if (null != myStylusPointDescription) //{ // textbox1.AppendText("StylusPointDescription\n"); // textbox1.AppendText(" Number of buttons: " + myStylusPointDescription.ButtonCount + "\n"); // // Buttons // for (int k = 0; k < myTabletDevice.StylusPacketDescription.ButtonCount; k++) // { // textbox1.AppendText(" Button[" + k + "] GUID: " + myStylusPointDescription.GetButton(k).ToString() + "\n"); // } // textbox1.AppendText(" Packet size: " + myStylusPointDescription.PacketSize + "\n"); // textbox1.AppendText(" Number of values: " + myStylusPointDescription.ValueCount + "\n"); // // Stylus metrics // ReadOnlyCollection<StylusPointPropertyInfo> myStylusPointProperties = // myStylusPointDescription.GetStylusPointProperties(); // // If metrics exist, display them // if (null != myStylusPointProperties) // { // for (int j = 0; j < myStylusPointProperties.Length; j++) // { // textbox1.AppendText(" Metric[" + j + "]\n"); // textbox1.AppendText(" Name: " + GetPacketValueName(myStylusPointProperties[j].Guid) + "\n"); // textbox1.AppendText(" Guid: " + myStylusPointProperties[j].Id.ToString() + "\n"); // textbox1.AppendText(" Min: " + myStylusPointProperties[j].Minimum.ToString() + "\n"); // textbox1.AppendText(" Max: " + myStylusPointProperties[j].Maximum.ToString() + "\n"); // textbox1.AppendText(" Unit: " + myStylusPointProperties[j].Unit.ToString() + "\n"); // textbox1.AppendText(" Resolution: " + myStylusPointProperties[j].Resolution.ToString() + "\n"); // textbox1.AppendText("\n"); // } // } //} //else //{ // textbox1.AppendText("StylusPacketDescription: null\n"); //} // <Snippet13> if (null != myTabletDevice.Target) { textbox1.AppendText("Target: " + myTabletDevice.Target.GetType().Name + "\n"); } else { textbox1.AppendText("Target: null\n"); } // </Snippet13> // <Snippet2> // Get the type of tablet device TabletDeviceType myTabletDeviceType = myTabletDevice.Type; // Display the type of tablet device textbox1.AppendText("Type: "); switch (myTabletDeviceType) { case TabletDeviceType.Stylus: textbox1.AppendText("Stylus\n"); break; default: // TabletDeviceType.Touch: textbox1.AppendText("Touch Pad\n"); break; } // </Snippet2> // Show output from TabletDevice.ToString() // <Snippet14> textbox1.AppendText("\n\nTablet Device:" + myTabletDevice.ToString() + "\n\n"); // </Snippet14> textbox1.AppendText("\n"); // <Snippet1> // Get the capabilities of the current tablet device TabletHardwareCapabilities myHWCaps = myTabletDevice.TabletHardwareCapabilities; // </Snippet1> // <Snippet26> if ((Tablet.CurrentTabletDevice.TabletHardwareCapabilities & TabletHardwareCapabilities.SupportsPressure) == TabletHardwareCapabilities.SupportsPressure) { textbox1.AppendText("The tablet can detect the pressure of the teblet pen."); } // </Snippet26> textbox1.AppendText("\n"); //// Get the current stylus, if it exists: //StylusDevice myStylusDevice = myTabletDevice.StylusDevices[0]; //// If stylus exists, print its properties //if (null != myStylusDevice) //{ // textbox1.AppendText("STYLUS\n\n"); // textbox1.AppendText("ActiveSource: " + GetStringOrNull(myStylusDevice.ActiveSource) + "\n"); // textbox1.AppendText("Captured: " + GetStringOrNull(myStylusDevice.Captured) + "\n"); // textbox1.AppendText("DirectlyOver: " + GetStringOrNull(myStylusDevice.DirectlyOver) + "\n"); // textbox1.AppendText("Dispatcher: " + GetStringOrNull(myStylusDevice.Dispatcher) + "\n"); // textbox1.AppendText("ID: " + GetStringOrNull(myStylusDevice.Id) + "\n"); // textbox1.AppendText("InAir: " + GetStringOrNull(myStylusDevice.InAir) + "\n"); // textbox1.AppendText("InRange: " + GetStringOrNull(myStylusDevice.InRange) + "\n"); // textbox1.AppendText("Inverted: " + GetStringOrNull(myStylusDevice.Inverted) + "\n"); // textbox1.AppendText("Name: " + GetStringOrNull(myStylusDevice.Name) + "\n"); // textbox1.AppendText("PacketCount: " + GetStringOrNull(myStylusDevice.GetPackets(null).PacketCount) + "\n"); // textbox1.AppendText("Tablet Device: " + GetStringOrNull(myStylusDevice.TabletDevice.Name) + "\n"); // textbox1.AppendText("Tablet Position: " + GetStringOrNull(myStylusDevice.GetPosition(null)) + "\n"); // textbox1.AppendText("Target: " + GetStringOrNull(myStylusDevice.Target) + "\n"); //} } }