-
Notifications
You must be signed in to change notification settings - Fork 70
/
keyboard.html
85 lines (62 loc) · 2.29 KB
/
keyboard.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
<title>A-Frame: Keyboard component</title>
<meta name="description" content="A-Frame Examples">
<script src="js/aframe-master-v1.3.0.min.js"></script>
<script src="js/aframe-environment-component.min.js"></script>
<script src="js/aframe-super-keyboard.min.js"></script>
</head>
<body>
<script>
AFRAME.registerComponent('keyboard-functions', {
init: function()
{
// for referencing issues
let self = this;
// set up event listeners
// input event triggered when user presses enter
this.el.addEventListener('superkeyboardinput', function(event)
{
let text = event.detail.value;
// text also accessible via: self.el.getAttribute("super-keyboard")["value"]
console.log("Input: " + text);
// clear the input bar (since keyboard is not disappearing)
self.el.setAttribute( "super-keyboard", "value", "" );
// change the color of the sphere
document.getElementById("sphere").setAttribute("color", text);
});
// dismiss event triggered when user closes keyboard
this.el.addEventListener('superkeyboarddismiss', function(event)
{
// repurpose close functionality to clear all input text without submitting
console.log("Input cleared.");
self.el.setAttribute( "super-keyboard", "value", "" );
});
},
tick: function (time, timeDelta)
{
// force keyboard to remain visible even after input or dismiss events triggered
if ( !this.el.object3D.visible )
this.el.object3D.visible = true;
}
});
</script>
<!-- https://github.com/supermedium/aframe-environment-component -->
<a-scene environment="preset: default;">
<a-entity id="mouseCursor" cursor="rayOrigin: mouse"></a-entity>
<a-entity id="hand" laser-controls="hand: right">
<a-sphere radius="0.03"></a-sphere>
</a-entity>
<!--
Documentation at https://github.com/supermedium/aframe-super-keyboard
Changeto "hand: #hand;" for VR.
imagePath: directory that contains image sk-basic.png
multipleInputs: show keyboard stay open after input is entered? (default: false)
-->
<a-entity id="keyboard" super-keyboard="hand: #mouseCursor; imagePath: images/;" keyboard-functions
position="0 1.25 -0.5" rotation="-30 0 0"></a-entity>
<a-sphere id="sphere" radius="2" position="0 2 -8" color="gray"></a-sphere>
</a-scene>
</body>
</html>