Turn pages with the arrow keys
Updated
A presenter’s screen shows a PDF slide deck; the left and right arrow keys turn its pages, stopping at the first and last, with the page count read from the PDF::ready event.
Click the view, then press the right and left arrow keys to turn the pages. The arrow keys do not move the camera here; drag to orbit, scroll to zoom.
Turn pages with the arrow keys
#pragma lifecycle(startup, update)
let deck;let pages = 1;
function startup() { deck = findEntity('Deck').getComponent(PDFComponent); deck.setProps({ controls: false, page: 1 });
on('deck', (event) => { if (event.eventType === EventType.PDF.Ready) pages = event.data.pages; });}
function update() { const page = deck.props.page; if (Input.keyboard.isKeyReleased(Key.ArrowRight) && page < pages) { deck.setProps({ page: page + 1 }); } if (Input.keyboard.isKeyReleased(Key.ArrowLeft) && page > 1) { deck.setProps({ page: page - 1 }); }}How it works
Section titled “How it works”The script is explained step by step in Turn pages with the arrow keys.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
DeckKeys.xrproj