2

How, in ReactVR app, can I detect when user click some specific key? I have a function for catching this event but when I put it on View component like this <View onInput={(e) => this.handleInput(e)}> it catch it only when I have my cursor on some component inside this view and I want to know this regardless of user cursor position or anything else.

Alan Wołejko
  • 442
  • 2
  • 5
  • 20

1 Answers1

0

Did you figure this out? I also want to do something similar.

For now I made a giant invisible <View> immediately in front of the camera, and used onInput there. I'll see if I can find a better solution, but for now that's what I am doing.

Edit: Some more progress (not sure how far you got)

handle(e) { 
  console.log('Event', e.nativeEvent.inputEvent)
}

<View 
  onInput={e => this.handle(e)}
  style={{
    transform: [{translate: [0, 0, -1]}],
    layoutOrigin: [0.5, 0.5]
  }}
</View>

My View is small, but you can play with the style.

The docs said I can use event.type, but that didn't work for me. I read about nativeEvent in this issue.

You can see many properties, like:

  • type
  • key (for Keyboard event)
  • viewportX and viewportY (for mouse event)

and so on.

The docs are not that in depth. I recommend reading Github issues a lot. Hopefully the docs and ecosystem will grow more soon. For now the best option is Stackoverflow, and spreading the knowledge we have figure out.

lmiller1990
  • 925
  • 2
  • 12
  • 22