You don't have to reinvent the wheel, there are great open source solutions that you can try to integrate into your project. Even if you don't want to do that, you can take a look into these solutions to have an understanding of how they implemented it:
three-mesh-ui has pre-built keyboard layouts, and has an integration example with THREE.Raycaster
Another alternative would be vr-keyboard which offers a solution for 3D on-screen input in VR.