public bool GetButtonUp(StylusButton stylusButton) { var native = GetButtonString(stylusButton); if (native != null) { if (stylusButton == StylusButton.Grip) { if (Input.GetAxis(native) > 0f) { _grabUpLastFrame = false; } else if (Input.GetAxis(native) == 0f && !_grabUpLastFrame) { LogitechToolkitManager.Instance.StartCoroutine(RunNextFrame(() => _grabUpLastFrame = true)); return(true); } return(false); } else { return(Input.GetKeyUp(native)); } } else { return(false); } }
internal PointerStylusDevice(PointerTabletDevice tabletDevice, UnsafeNativeMethods.POINTER_DEVICE_CURSOR_INFO cursorInfo) { _cursorInfo = cursorInfo; _tabletDevice = tabletDevice; _pointerLogic = StylusLogic.GetCurrentStylusLogicAs <PointerLogic>(); // Touch devices have a special set of handling code if (tabletDevice.Type == TabletDeviceType.Touch) { TouchDevice = new PointerTouchDevice(this); } _interactionEngine = new PointerInteractionEngine(this); _interactionEngine.InteractionDetected += HandleInteraction; List <StylusButton> buttons = new List <StylusButton>(); // Create a button collection for this StylusDevice based off the button properties stored in the tablet // This needs to be done as each button instance has a StylusDevice owner that it uses to access the raw // data in the StylusDevice. foreach (var prop in _tabletDevice.DeviceInfo.StylusPointProperties) { if (prop.IsButton) { StylusButton button = new StylusButton(StylusPointPropertyIds.GetStringRepresentation(prop.Id), prop.Id); button.SetOwner(this); buttons.Add(button); } } _stylusButtons = new StylusButtonCollection(buttons); }
public bool GetButton(StylusButton stylusButton) { if (stylusButton == StylusButton.TouchstripTouch) { return(GetBooleanActionFromMap(stylusButton).GetState(InputSource) && GetRejectionStatus(StylusAxisInput.TrackpadY)); } return(GetBooleanActionFromMap(stylusButton).GetState(InputSource)); }
// This isn't hooked up to anything. // <Snippet24> void OnStylusButtonDown(object sender, StylusButtonEventArgs e) { StylusButton myStylusButton = e.StylusButton; if (myStylusButton.Guid == StylusPointProperties.BarrelButton.Id) { // the barrel button on the stylus has been pressed } }
private SteamVR_Action_Boolean GetBooleanActionFromMap(StylusButton stylusButton) { SteamVR_Action_Boolean actionBoolean; if (_stylusButtonsToSteamVrMap.TryGetValue(stylusButton, out actionBoolean)) { return(actionBoolean); } Debug.LogErrorFormat("No SteamVR action could be found for button {0}", stylusButton); return(null); }
//</Snippet7> //<Snippet23> void textbox1_StylusInRange(object sender, StylusEventArgs e) { StylusButtonCollection buttons = e.StylusDevice.StylusButtons; StylusButton barrelButton = buttons.GetStylusButtonByGuid(StylusPointProperties.BarrelButton.Id); if (barrelButton != null) { textbox1.AppendText(barrelButton.StylusButtonState.ToString()); } textbox1.AppendText("\r\n"); }
private void GeneralButtonEventHandler(StylusButtonEventArgs e, bool isPressed) { StylusButton myStylusButton = e.StylusButton; if (myStylusButton.Guid == StylusPointProperties.BarrelButton.Id) { currentApp.tabletState.Update("/input/stylus/barrel/click", isPressed); } else if (myStylusButton.Guid == StylusPointProperties.SecondaryTipButton.Id) { currentApp.tabletState.Update("/input/stylus/eraser/click", isPressed); } e.Handled = true; }
// Note: grab button is mapped to an axis whose value is either 0.0 or 1.0 for Vive (for Oculus analog grab // compatibility) which makes it a bit more tedious to get the input below. public bool GetButton(StylusButton stylusButton) { var native = GetButtonString(stylusButton); if (native != null) { if (stylusButton == StylusButton.Grip) { return(Input.GetAxis(native) > 0f); } else { return(Input.GetKey(native)); } } else { return(false); } }
/// <summary> /// Tries to translate a given Stylus button to its native Unity string (e.g. "joystick button N"). /// </summary> /// <param name="stylusButton">The button to translate.</param> /// <returns>The corresponding string, or null if none could be found.</returns> private string GetButtonString(StylusButton stylusButton) { var mapToUse = _buttonsToJoystickMapLeft; if (StylusHand == Handedness.Primary) { mapToUse = _buttonsToJoystickMapRight; } string native; if (mapToUse.TryGetValue(stylusButton, out native)) { return(native); } else { Debug.LogErrorFormat("No native Unity button could be found for {0}", stylusButton); return(null); } }
// 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> }
public InputTrigger(TrackedDeviceProvider trackedDeviceProvider, StylusButton stylusButton, EButtonEvent inputButtonEvent) { TrackedDeviceProvider = trackedDeviceProvider; StylusButton = stylusButton; InputButtonEvent = inputButtonEvent; }
public bool GetButtonUp(StylusButton stylusButton) { return(GetBooleanActionFromMap(stylusButton).GetStateUp(InputSource)); }
public bool GetButtonUp(StylusButton stylusButton) { return(Controller.GetButtonUp(stylusButton)); }