Navigation

  • ☰
  • VRED Python API v2 documentation »
  • VRED Python examples »

Print the current finger position on the touchpad¶

Shows how a device interaction can be implemented, that uses the touchpad of a VR controller. Further information on how a custom interaction can be implemented is shown in the “Implementation of a custom device interaction” example.

This device interaction creates two device actions, which are triggered when the touchpad is touched, or when the touch ends. When the touch starts, the moved signal of the controller is connected to a method that prints the position of the finger on the touchpad. The information about the position is part of the button state and can be queried from the device.

25padPosition = device.getButtonState("Touchpad").getPosition()

The moved signal is disconnectd, when the touchpad is not touched anymore, which ends the printing of the position.

vr/printTouchpadPosition.py¶
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3class pad:
 4    def __init__(self):
 5        self.readPadPosition = False
 6        self.currentController = ""        
 7
 8        # Create an intreraction
 9        self.padInteraction = vrDeviceService.createInteraction("PadInteraction")
10        # Set an interaction group that is supported, as other groups already use the touchpad
11        self.padInteraction.setSupportedInteractionGroups(["PadMode"])
12
13        # Get the actions that will be used
14        self.enableAction = self.padInteraction.createControllerAction("any-touchpad-touched")
15        self.disableAction = self.padInteraction.createControllerAction("any-touchpad-untouched")        
16
17        # Connect to the methods that will de-/activate the reading of the touchpad position
18        # and the actual printing
19        self.enableAction.signal().triggered.connect(self.enablePad)
20        self.disableAction.signal().triggered.connect(self.disablePad)        
21
22        # Set the interaction group active
23        vrDeviceService.setActiveInteractionGroup("PadMode")
24
25    def printPosition(self, device):                
26        # Get the position of the finger on the touchpad and print it
27        padPosition = device.getButtonState("Touchpad").getPosition()
28        print(("Touchpad position: " + str(padPosition.x()) + " " + str(padPosition.y())))
29
30    def enablePad(self, action, device):                
31        # If position reading is already active, do not do anything
32        if self.readPadPosition:
33            return
34
35        # Store which controller is currently used
36        self.currentController = device.getName()
37        # Activate the reading
38        self.readPadPosition = True
39        device.signal().moved.connect(self.printPosition)
40
41    def disablePad(self, action, device):
42        # If position reading is not active, do not do anything
43        if not self.readPadPosition:
44            return
45
46        # Check if this is the controller that activated the position printing
47        if self.currentController != device.getName():
48            return
49        
50        # Deactivate the position reading and printing
51        self.readPadPosition = False
52        device.signal().moved.disconnect(self.printPosition)
53    
54thePad = pad()

Quick search

Table Of Contents

  • VRED Python examples
    • Animations
    • Annotations
    • Cameras
    • Collision detection
    • Connector
    • Constraints
    • File Import and Export
    • Geometry
    • Lightmaps
    • Materials
    • Measurement
    • Metadata
    • Physics
    • Programming
    • Rendering
    • Sceneplates
    • Scenetree
    • Sound
    • User input
    • User interface
    • vrMenu
    • Virtual Reality Device Interaction
    • Virtual Reality Device Handling
    • Virtual Reality Immersive Tools
    • Virtual Reality Script Plugins
    • Virtual Reality Collaboration
    • Virtual Reality Hands
    • Deprecated Virtual Reality Examples
    • Deprecated Scenetree Examples
    • Other Script Plugins
    • Uncategorized
    • Snippets
    • Deprecated Snippets
  • Node graphs in VRED
  • What’s new in VRED Python API v2
  • vrAnnotationService
  • vrAnnotationTypes
  • vrAssetsService
  • vrBakeService
  • vrBakeTypes
  • vrCADFileTypes
  • vrCameraFromAtUp
  • vrCameraService
  • vrCameraTypes
  • vrClusterManagerService
  • vrClusterService
  • vrClusterTypes
  • vrConstraintService
  • vrDecoreService
  • vrDeviceService
  • vrFileIOService
  • vrFileTypes
  • vrGPUService
  • vrGPUTypes
  • vrGUIService
  • vrGeometryService
  • vrGeometryTypes
  • vrHMDService
  • vrHandTypes
  • vrImageService
  • vrImageTypes
  • vrImmersiveInteractionService
  • vrImmersiveInteractionTypes
  • vrImmersiveUiService
  • vrLensFlareTypes
  • vrLightService
  • vrLightTypes
  • vrLogService
  • vrLogTypes
  • vrMaterialEntry
  • vrMaterialEntryId
  • vrMaterialEntryType
  • vrMaterialService
  • vrMaterialTypes
  • vrMathService
  • vrMetadataService
  • vrMetadataTypes
  • vrNodeService
  • vrObjectService
  • vrPhysicsService
  • vrPhysicsTypes
  • vrProgressService
  • vrQueryService
  • vrReferenceService
  • vrReferenceTypes
  • vrRenderTypes
  • vrRoughnessTextureTypes
  • vrScenegraphService
  • vrScenegraphTypes
  • vrSceneplateService
  • vrSceneplateTypes
  • vrSessionService
  • vrSpectrum
  • vrStyleTypes
  • vrSubstanceTypes
  • vrTextureTypes
  • vrTransformTypes
  • vrUVService
  • vrUVTypes
  • vrUndoService
  • vrUserMimeTypes
  • vrVRInputDeviceTypes
  • vrWebEngineService
  • vrXRealityTypes
  • vrdAimConstraintNode
  • vrdAnalyticSettings
  • vrdAnnotationNode
  • vrdAreaLightCone
  • vrdAreaLightNode
  • vrdAtfSettings
  • vrdBRDFCommonSettings
  • vrdBRDFMaterial
  • vrdBaseLightNode
  • vrdBaseLightProfile
  • vrdBillboardNode
  • vrdBlendChunk
  • vrdBoundingBox
  • vrdBrushOrientation
  • vrdBrushedMetalMaterial
  • vrdBsdfMeasurement
  • vrdBumpTexture
  • vrdButtonState
  • vrdCameraBaseNode
  • vrdCameraCollider
  • vrdCameraNode
  • vrdCameraTrackNode
  • vrdCarbon2DMaterial
  • vrdCarbonMaterial
  • vrdCarbonPattern
  • vrdCarbonPattern2D
  • vrdCarbonPattern3D
  • vrdChromeMaterial
  • vrdChunkMaterial
  • vrdClearcoat
  • vrdClipPlaneNode
  • vrdColorCorrection
  • vrdConstraintNode
  • vrdCubeTextureChunk
  • vrdDecoreSettings
  • vrdDeltaLightNode
  • vrdDepthTestChunk
  • vrdDeviceAction
  • vrdDeviceActionSignal
  • vrdDeviceInteraction
  • vrdDeviceMessageData
  • vrdDirectionalLightNode
  • vrdDiskLightNode
  • vrdDisplacement
  • vrdDisplacementTexture
  • vrdDistanceLODNode
  • vrdEnvironmentColorCorrection
  • vrdEnvironmentMaterial
  • vrdEnvironmentNode
  • vrdEnvironmentRaytracingSettings
  • vrdEnvironmentShadowsAndIllumination
  • vrdEnvironmentSwitchMaterial
  • vrdEnvironmentTransformation
  • vrdEyeGaze
  • vrdFileExportSettings
  • vrdFindOptions
  • vrdFlakeLayer
  • vrdFlipflopCarpaintMaterial
  • vrdFlipflopFlakeLayer
  • vrdFoveatedQuality
  • vrdGLSLShaderChunk
  • vrdGLSLShaderParameter
  • vrdGLSLShaderParameterInt
  • vrdGLSLShaderParameterList
  • vrdGLSLShaderParameterMatrix
  • vrdGLSLShaderParameterReal
  • vrdGLSLShaderParameterVec2f
  • vrdGLSLShaderParameterVec3f
  • vrdGLSLShaderParameterVec4f
  • vrdGeometryNode
  • vrdGlassMaterial
  • vrdGpuInfo
  • vrdGpuStateInfo
  • vrdGradingLut
  • vrdGradingPrimary
  • vrdGradingRGBMCurve
  • vrdGradingTone
  • vrdHDRLightStudio
  • vrdHostSwitchNode
  • vrdIlluminationBakeSettings
  • vrdImage
  • vrdImmersiveMenu
  • vrdImmersiveTool
  • vrdImmersiveToolSignal
  • vrdIncandescence
  • vrdLayeredMaterial
  • vrdLensFlareEffect
  • vrdLensFlareElement
  • vrdLensFlareFxElement
  • vrdLensFlareGhost
  • vrdLensFlareGhostLine
  • vrdLensFlareGlow
  • vrdLensFlareRing
  • vrdLensFlareStar
  • vrdLensFlareStreak
  • vrdLightLinkSetNode
  • vrdLightPortalMaterial
  • vrdLightProfile
  • vrdLightTexture
  • vrdLightTransform
  • vrdLightmap
  • vrdLineChromeMaterial
  • vrdLineChunk
  • vrdLinearGradient
  • vrdLinearGradientStop
  • vrdMDLMaterial
  • vrdMDLProperties
  • vrdMarker
  • vrdMaterial
  • vrdMaterialChunk
  • vrdMaterialChunkList
  • vrdMaterialList
  • vrdMaterialNode
  • vrdMaterialPoolNode
  • vrdMaterialRaytracingSettings
  • vrdMaterialXMaterial
  • vrdMaterialXProperties
  • vrdMatrixTransformNode
  • vrdMeasuredCarpaintMaterial
  • vrdMeasuredMaterial
  • vrdMetadata
  • vrdMetadataEntry
  • vrdMetadataEntryList
  • vrdMetadataSet
  • vrdMetallicCarpaintMaterial
  • vrdMultiMarker
  • vrdMultiMaterial
  • vrdMultiPassMaterial
  • vrdNPRSettings
  • vrdNode
  • vrdNodeInfo
  • vrdNodeList
  • vrdOCSMaterial
  • vrdObject
  • vrdObjectList
  • vrdObjectSignal
  • vrdOpenGLInfo
  • vrdOpenVDBMaterial
  • vrdOrientationConstraintNode
  • vrdParentConstraintNode
  • vrdPerspectiveMatch
  • vrdPhongMaterial
  • vrdPhysicsConfig
  • vrdPhysicsConvexConfig
  • vrdPhysicsHullConfig
  • vrdPhysicsInfo
  • vrdPhysicsTrianglesConfig
  • vrdPlasticMaterial
  • vrdPointLightNode
  • vrdPolygonChunk
  • vrdPositionConstraintNode
  • vrdProjectMergeSettings
  • vrdRayFile
  • vrdRayFileInfo
  • vrdRayIntersection
  • vrdRayLightNode
  • vrdRaytracingInfo
  • vrdRectangularLightNode
  • vrdReferenceNode
  • vrdReflectivePlasticMaterial
  • vrdRoughnessTexture
  • vrdRoundedEdges
  • vrdSVBRDFMaterial
  • vrdSceneImportSettings
  • vrdSceneItemInfo
  • vrdSceneObject
  • vrdSceneplateNode
  • vrdSessionUser
  • vrdShadowMap
  • vrdShadowMaterial
  • vrdSkylightLocation
  • vrdSkylightMaterial
  • vrdSkylightSkyAndSun
  • vrdSoundNode
  • vrdSoundObstructorNode
  • vrdSphereEnvironmentMaterial
  • vrdSphericalLightNode
  • vrdSpotLightNode
  • vrdStereoSwitchNode
  • vrdSubstanceEnvironmentMaterial
  • vrdSubstanceMaterial
  • vrdSubstancePreset
  • vrdSubstanceProperties
  • vrdSubsurfaceScattering
  • vrdSurfaceNode
  • vrdSwitchMaterial
  • vrdSwitchNode
  • vrdTessellationSettings
  • vrdTexture
  • vrdTextureBake
  • vrdTextureBakeSettings
  • vrdTextureChunk
  • vrdTextureSettings
  • vrdTireMaterial
  • vrdTireTextureSettings
  • vrdTonemapper
  • vrdTrackedHand
  • vrdTransformNode
  • vrdTransformNodeVariant
  • vrdTransparency
  • vrdTurntable
  • vrdUVBaseProjectionSettings
  • vrdUVCylindricalProjectionSettings
  • vrdUVLayoutSettings
  • vrdUVOptimizeSettings
  • vrdUVPlanarProjectionSettings
  • vrdUVSeamSettings
  • vrdUVTriplanarProjectionSettings
  • vrdUVUnfoldSettings
  • vrdUiEngine
  • vrdUnicolorCarpaintMaterial
  • vrdVRDevice
  • vrdVRDeviceSignal
  • vrdVarjoRenderSettings
  • vrdVelvetMaterial
  • vrdVertexBake
  • vrdVertexBakeSettings
  • vrdViewpointNode
  • vrdVirtualTouchpadButton
  • vrdVolumeMaterial
  • vrdVolumeNode
  • vrdVolumeScatterMaterial
  • vrdWebEngine
  • vrdWovenClothMaterial
  • vrdXRayMaterial
  • vrdXRiteMeasuredMaterial

Previous topic

Print the serial number of a device

Next topic

Switch the visualization mode of a VR device

Navigation

  • index
  • next |
  • previous |
© Copyright 2024, Autodesk Inc.. Created using Sphinx 4.0.2.