{"id":6814,"date":"2025-09-24T15:12:34","date_gmt":"2025-09-24T19:12:34","guid":{"rendered":"https:\/\/stepinto.vision\/?p=6814"},"modified":"2025-09-27T06:31:36","modified_gmt":"2025-09-27T10:31:36","slug":"reading-input-data-from-manipulation-component","status":"publish","type":"post","link":"https:\/\/stepinto.vision\/example-code\/reading-input-data-from-manipulation-component\/","title":{"rendered":"Reading input data from Manipulation Component"},"content":{"rendered":"\n<p>We can use chirality and kind to customize input based on the user&#8217;s hand or input device.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>We&#8217;ve covered a lot on Manipulation Component. See our previous posts to learn how to get started.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/stepinto.vision\/example-code\/getting-started-with-manipulation-component\/\">Getting started with Manipulation Component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/stepinto.vision\/example-code\/using-events-with-manipulation-component\/\">Using events with Manipulation Component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/stepinto.vision\/example-code\/using-custom-sounds-with-manipulation-component\/\">Using custom sounds with Manipulation Component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/stepinto.vision\/example-code\/redirect-input-with-manipulation-component\/\">Redirect input with Manipulation Component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/stepinto.vision\/example-code\/constrain-position-with-manipulationcomponent\/\">Constrain position with Manipulation Component<\/a><\/li>\n<\/ul>\n\n\n\n<p>Manipulation Component can surface some additional data such as <code>chirality<\/code> (left or right hand), <code>kind<\/code> (input type). We can read this during a Manipulation Event by checking the <a href=\"https:\/\/developer.apple.com\/documentation\/realitykit\/manipulationcomponent\/inputdevice\/kind-swift.enum\">InputDevice<\/a>. For example,<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>_ = content.subscribe(to: ManipulationEvents.WillBegin.self) { event in\n  guard let inputDevice = event.inputDeviceSet.first else { return }\n  \n  let chirality = inputDevice.chirality\n  let kind = inputDevice.kind\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #001080\">_<\/span><span style=\"color: #000000\"> = content.<\/span><span style=\"color: #795E26\">subscribe<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">to<\/span><span style=\"color: #000000\">: ManipulationEvents.<\/span><span style=\"color: #001080\">WillBegin<\/span><span style=\"color: #000000\">.self) { event <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #AF00DB\">guard<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> inputDevice = event.<\/span><span style=\"color: #001080\">inputDeviceSet<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">first<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">else<\/span><span style=\"color: #000000\"> { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> chirality = inputDevice.<\/span><span style=\"color: #001080\">chirality<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">  <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> kind = inputDevice.<\/span><span style=\"color: #001080\">kind<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This can be useful when we need different behaviors for left vs. right hands. Or perhaps we want to apply components based on input type. For example, in Project Graveyard, I add a Billboard component when a user starts manipulating an entity. It looks great when using <code>indirectPinch<\/code>, but it seems kind of odd when using <code>directPinch<\/code>. I plan to update my app to check the kind and only add the Billboard when it is needed.<\/p>\n\n\n\n<p>For this article, we&#8217;ll write the kind to either a left or right variable.<\/p>\n\n\n\n\t\t<figure class=\"wp-block-jetpack-videopress jetpack-videopress-player\" style=\"\" >\n\t\t\t<div class=\"jetpack-videopress-player__wrapper\"> <div class=\"jetpack-video-wrapper\"><iframe title=\"VideoPress Video Player\" aria-label='VideoPress Video Player' width='720' height='405' src='https:\/\/videopress.com\/embed\/xdjFrrvq?cover=1&amp;autoPlay=0&amp;controls=1&amp;loop=0&amp;muted=0&amp;persistVolume=1&amp;playsinline=0&amp;preloadContent=metadata&amp;useAverageColor=1&amp;hd=0' frameborder='0' allowfullscreen data-resize-to-parent=\"true\" allow='clipboard-write'><\/iframe><script src='https:\/\/v0.wordpress.com\/js\/next\/videopress-iframe.js?m=1739540970'><\/script><\/div><\/div>\n\t\t\t\n\t\t\t\n\t\t<\/figure>\n\t\t\n\n\n<h2 class=\"wp-block-heading\">Example Code<\/h2>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#000000;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#000000;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>struct Example104: View {\n\n    @State private var leftKind = \"\"\n    @State private var rightKind = \"\"\n\n    var body: some View {\n        RealityView { content in\n\n            let subject = createStepDemoBox()\n\n            \/\/ We'll use configureEntity to set up input and collision on the subject\n            ManipulationComponent\n                .configureEntity(\n                    subject,\n                    hoverEffect: .spotlight(.default),\n                    collisionShapes: &#91;.generateBox(width: 0.25, height: 0.25, depth: 0.25)&#93;\n                )\n\n            _ = content.subscribe(to: ManipulationEvents.WillBegin.self) { event in\n                guard let inputDevice = event.inputDeviceSet.first else { return }\n                unpackChirality(inputDevice.chirality, value: unpackKind(inputDevice.kind)) \/\/ track the kind per hand\/device\n            }\n\n            _ = content.subscribe(to: ManipulationEvents.DidHandOff.self) { event in\n                guard let oldInputDeviceSet = event.oldInputDeviceSet.first else { return }\n                unpackChirality(oldInputDeviceSet.chirality, value: \"\") \/\/ track the kind per hand\/device\n                guard let newInputDeviceSet = event.newInputDeviceSet.first else { return }\n                unpackChirality(newInputDeviceSet.chirality, value: unpackKind(newInputDeviceSet.kind)) \/\/ track the kind per hand\/device\n            }\n\n            _ = content.subscribe(to: ManipulationEvents.WillRelease.self) { event in\n                guard let inputDevice = event.inputDeviceSet.first else { return }\n                unpackChirality(inputDevice.chirality, value: \"\") \/\/ clear the correct value on release\n            }\n\n            content.add(subject)\n\n        }\n        .ornament(attachmentAnchor: .scene(.topLeading), ornament: {\n            Text(leftKind)\n                .frame(width: 160)\n                .padding()\n                .background(leftKind.isEmpty ? .clear : .green)\n                .glassBackgroundEffect()\n        })\n\n        .ornament(attachmentAnchor: .scene(.topTrailing), ornament: {\n            Text(rightKind)\n                .frame(width: 160)\n                .padding()\n                .background(rightKind.isEmpty ? .clear : .green)\n                .glassBackgroundEffect()\n        })\n    }\n\n    func unpackChirality(_ chirality: ManipulationComponent.InputDevice.Chirality?, value: String) {\n        switch chirality {\n        case .left:\n            leftKind = value\n        case .right:\n            rightKind = value\n        case .none:\n            return\n        @unknown default:\n            return\n        }\n\n    }\n\n    func unpackKind(_ kind: ManipulationComponent.InputDevice.Kind) -> String {\n        switch kind {\n        case .pointer:\n            return \"pointer\"\n        case .directPinch:\n            return \"directPinch\"\n        case .indirectPinch:\n            return \"indirectPinch\"\n        default:\n            return \"\"\n        }\n    }\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki light-plus\" style=\"background-color: #FFFFFF\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #0000FF\">struct<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #267F99\">Example104<\/span><span style=\"color: #000000\">: View {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">@State<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">private<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> leftKind = <\/span><span style=\"color: #A31515\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">@State<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">private<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> rightKind = <\/span><span style=\"color: #A31515\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">var<\/span><span style=\"color: #000000\"> body: some View {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        RealityView { content <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> subject = <\/span><span style=\"color: #795E26\">createStepDemoBox<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #008000\">\/\/ We&#39;ll use configureEntity to set up input and collision on the subject<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            ManipulationComponent<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">configureEntity<\/span><span style=\"color: #000000\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    subject,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    <\/span><span style=\"color: #795E26\">hoverEffect<\/span><span style=\"color: #000000\">: .<\/span><span style=\"color: #795E26\">spotlight<\/span><span style=\"color: #000000\">(.<\/span><span style=\"color: #001080\">default<\/span><span style=\"color: #000000\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                    <\/span><span style=\"color: #795E26\">collisionShapes<\/span><span style=\"color: #000000\">: &#91;.<\/span><span style=\"color: #795E26\">generateBox<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">width<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.25<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">height<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.25<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">depth<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">0.25<\/span><span style=\"color: #000000\">)&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                )<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #001080\">_<\/span><span style=\"color: #000000\"> = content.<\/span><span style=\"color: #795E26\">subscribe<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">to<\/span><span style=\"color: #000000\">: ManipulationEvents.<\/span><span style=\"color: #001080\">WillBegin<\/span><span style=\"color: #000000\">.self) { event <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #AF00DB\">guard<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> inputDevice = event.<\/span><span style=\"color: #001080\">inputDeviceSet<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">first<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">else<\/span><span style=\"color: #000000\"> { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">unpackChirality<\/span><span style=\"color: #000000\">(inputDevice.<\/span><span style=\"color: #001080\">chirality<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">value<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #795E26\">unpackKind<\/span><span style=\"color: #000000\">(inputDevice.<\/span><span style=\"color: #001080\">kind<\/span><span style=\"color: #000000\">)) <\/span><span style=\"color: #008000\">\/\/ track the kind per hand\/device<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #001080\">_<\/span><span style=\"color: #000000\"> = content.<\/span><span style=\"color: #795E26\">subscribe<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">to<\/span><span style=\"color: #000000\">: ManipulationEvents.<\/span><span style=\"color: #001080\">DidHandOff<\/span><span style=\"color: #000000\">.self) { event <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #AF00DB\">guard<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> oldInputDeviceSet = event.<\/span><span style=\"color: #001080\">oldInputDeviceSet<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">first<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">else<\/span><span style=\"color: #000000\"> { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">unpackChirality<\/span><span style=\"color: #000000\">(oldInputDeviceSet.<\/span><span style=\"color: #001080\">chirality<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">value<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #A31515\">&quot;&quot;<\/span><span style=\"color: #000000\">) <\/span><span style=\"color: #008000\">\/\/ track the kind per hand\/device<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #AF00DB\">guard<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> newInputDeviceSet = event.<\/span><span style=\"color: #001080\">newInputDeviceSet<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">first<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">else<\/span><span style=\"color: #000000\"> { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">unpackChirality<\/span><span style=\"color: #000000\">(newInputDeviceSet.<\/span><span style=\"color: #001080\">chirality<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">value<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #795E26\">unpackKind<\/span><span style=\"color: #000000\">(newInputDeviceSet.<\/span><span style=\"color: #001080\">kind<\/span><span style=\"color: #000000\">)) <\/span><span style=\"color: #008000\">\/\/ track the kind per hand\/device<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #001080\">_<\/span><span style=\"color: #000000\"> = content.<\/span><span style=\"color: #795E26\">subscribe<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">to<\/span><span style=\"color: #000000\">: ManipulationEvents.<\/span><span style=\"color: #001080\">WillRelease<\/span><span style=\"color: #000000\">.self) { event <\/span><span style=\"color: #AF00DB\">in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #AF00DB\">guard<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000FF\">let<\/span><span style=\"color: #000000\"> inputDevice = event.<\/span><span style=\"color: #001080\">inputDeviceSet<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #001080\">first<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">else<\/span><span style=\"color: #000000\"> { <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                <\/span><span style=\"color: #795E26\">unpackChirality<\/span><span style=\"color: #000000\">(inputDevice.<\/span><span style=\"color: #001080\">chirality<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #795E26\">value<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #A31515\">&quot;&quot;<\/span><span style=\"color: #000000\">) <\/span><span style=\"color: #008000\">\/\/ clear the correct value on release<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            content.<\/span><span style=\"color: #795E26\">add<\/span><span style=\"color: #000000\">(subject)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        .<\/span><span style=\"color: #795E26\">ornament<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">attachmentAnchor<\/span><span style=\"color: #000000\">: .<\/span><span style=\"color: #795E26\">scene<\/span><span style=\"color: #000000\">(.<\/span><span style=\"color: #001080\">topLeading<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">ornament<\/span><span style=\"color: #000000\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #795E26\">Text<\/span><span style=\"color: #000000\">(leftKind)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">frame<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">width<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">160<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">padding<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">background<\/span><span style=\"color: #000000\">(leftKind.<\/span><span style=\"color: #001080\">isEmpty<\/span><span style=\"color: #000000\"> ? .<\/span><span style=\"color: #001080\">clear<\/span><span style=\"color: #000000\"> : .<\/span><span style=\"color: #001080\">green<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">glassBackgroundEffect<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        })<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        .<\/span><span style=\"color: #795E26\">ornament<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">attachmentAnchor<\/span><span style=\"color: #000000\">: .<\/span><span style=\"color: #795E26\">scene<\/span><span style=\"color: #000000\">(.<\/span><span style=\"color: #001080\">topTrailing<\/span><span style=\"color: #000000\">), <\/span><span style=\"color: #795E26\">ornament<\/span><span style=\"color: #000000\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #795E26\">Text<\/span><span style=\"color: #000000\">(rightKind)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">frame<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">width<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #098658\">160<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">padding<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">background<\/span><span style=\"color: #000000\">(rightKind.<\/span><span style=\"color: #001080\">isEmpty<\/span><span style=\"color: #000000\"> ? .<\/span><span style=\"color: #001080\">clear<\/span><span style=\"color: #000000\"> : .<\/span><span style=\"color: #001080\">green<\/span><span style=\"color: #000000\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">                .<\/span><span style=\"color: #795E26\">glassBackgroundEffect<\/span><span style=\"color: #000000\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        })<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">func<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">unpackChirality<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">_<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">chirality<\/span><span style=\"color: #000000\">: ManipulationComponent.InputDevice.Chirality?, <\/span><span style=\"color: #795E26\">value<\/span><span style=\"color: #000000\">: <\/span><span style=\"color: #267F99\">String<\/span><span style=\"color: #000000\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">switch<\/span><span style=\"color: #000000\"> chirality {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">left<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            leftKind = value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">right<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            rightKind = value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">none<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #0000FF\">@unknown<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #AF00DB\">default<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    <\/span><span style=\"color: #0000FF\">func<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #795E26\">unpackKind<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #795E26\">_<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #001080\">kind<\/span><span style=\"color: #000000\">: ManipulationComponent.InputDevice.Kind) -&gt; <\/span><span style=\"color: #267F99\">String<\/span><span style=\"color: #000000\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">switch<\/span><span style=\"color: #000000\"> kind {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">pointer<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #A31515\">&quot;pointer&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">directPinch<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #A31515\">&quot;directPinch&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">case<\/span><span style=\"color: #000000\"> .<\/span><span style=\"color: #001080\">indirectPinch<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #A31515\">&quot;indirectPinch&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        <\/span><span style=\"color: #AF00DB\">default<\/span><span style=\"color: #000000\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">            <\/span><span style=\"color: #AF00DB\">return<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #A31515\">&quot;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #000000\">}<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We can use chirality and kind to customize input based on the user&#8217;s hand or input device.<\/p>\n","protected":false},"author":93705089,"featured_media":6816,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[1365],"tags":[],"class_list":["post-6814","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-example-code"],"jetpack_publicize_connections":[],"taxonomy_info":{"category":[{"value":1365,"label":"Example Code"}]},"featured_image_src_large":["https:\/\/i0.wp.com\/stepinto.vision\/wp-content\/uploads\/2025\/09\/step-example-104-01.jpeg?fit=1024%2C576&ssl=1",1024,576,true],"author_info":{"display_name":"Joseph Simpson","author_link":"https:\/\/stepinto.vision\/author\/vrhermit\/"},"comment_info":0,"category_info":[{"term_id":1365,"name":"Example Code","slug":"example-code","term_group":0,"term_taxonomy_id":11,"taxonomy":"category","description":"Code snippets and examples of using common APIs throughout visionOS development","parent":0,"count":187,"filter":"raw","cat_ID":1365,"category_count":187,"category_description":"Code snippets and examples of using common APIs throughout visionOS development","cat_name":"Example Code","category_nicename":"example-code","category_parent":0}],"tag_info":false,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/stepinto.vision\/wp-content\/uploads\/2025\/09\/step-example-104-01.jpeg?fit=1920%2C1080&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/6814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/users\/93705089"}],"replies":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/comments?post=6814"}],"version-history":[{"count":8,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/6814\/revisions"}],"predecessor-version":[{"id":6867,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/posts\/6814\/revisions\/6867"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/media\/6816"}],"wp:attachment":[{"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/media?parent=6814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/categories?post=6814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stepinto.vision\/wp-json\/wp\/v2\/tags?post=6814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}