forked from novnc/noVNC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput.html
128 lines (113 loc) · 4.72 KB
/
input.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head><title>Input Test</title></head>
<body>
<br><br>
Canvas:
<span id="button-selection" style="display: none;">
<input id="button1" type="button" value="L"><input id="button2" type="button" value="M"><input id="button4" type="button" value="R">
</span>
<br>
<canvas id="canvas" width="640" height="20"
style="border-style: dotted; border-width: 1px;">
Canvas not supported.
</canvas>
<br>
Results:<br>
<textarea id="messages" style="font-size: 9;" cols=80 rows=25></textarea>
</body>
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script src="../core/util.js"></script>
<script src="../app/webutil.js"></script>
<script src="../core/base64.js"></script>
<script src="../core/input/keysym.js"></script>
<script src="../core/input/keysymdef.js"></script>
<script src="../core/input/xtscancodes.js"></script>
<script src="../core/input/vkeys.js"></script>
<script src="../core/input/util.js"></script>
<script src="../core/input/keyboard.js"></script>
<script src="../core/input/mouse.js"></script>
<script src="../core/display.js"></script>
<script>
var msg_cnt = 0, iterations,
width = 400, height = 200,
canvas, keyboard, mouse;
var newline = "\n";
function message(str) {
console.log(str);
cell = document.getElementById('messages');
cell.textContent += msg_cnt + ": " + str + newline;
cell.scrollTop = cell.scrollHeight;
msg_cnt++;
}
function mouseButton(x, y, down, bmask) {
msg = 'mouse x,y: ' + x + ',' + y + ' down: ' + down;
msg += ' bmask: ' + bmask;
message(msg);
}
function mouseMove(x, y) {
msg = 'mouse x,y: ' + x + ',' + y;
//console.log(msg);
}
function rfbKeyEvent(keysym, code, down) {
var d = down ? "down" : " up ";
var msg = "RFB key event " + d + " keysym: " + keysym + " code: " + code;
message(msg);
}
function rawKey(e) {
msg = "raw key event " + e.type +
" (key: " + e.keyCode + ", char: " + e.charCode +
", which: " + e.which +")";
message(msg);
}
function selectButton(num) {
var b, blist = [1,2,4];
if (typeof num === 'undefined') {
// Show the default
num = mouse.get_touchButton();
} else if (num === mouse.get_touchButton()) {
// Set all buttons off (no clicks)
mouse.set_touchButton(0);
num = 0;
} else {
// Turn on one button
mouse.set_touchButton(num);
}
for (b = 0; b < blist.length; b++) {
if (blist[b] === num) {
document.getElementById('button' + blist[b]).style.backgroundColor = "black";
document.getElementById('button' + blist[b]).style.color = "lightgray";
} else {
document.getElementById('button' + blist[b]).style.backgroundColor = "";
document.getElementById('button' + blist[b]).style.color = "";
}
}
}
window.onload = function() {
canvas = new Display({'target' : document.getElementById('canvas')});
keyboard = new Keyboard({'target': document,
'onKeyEvent': rfbKeyEvent});
document.addEventListener('keypress', rawKey);
document.addEventListener('keydown', rawKey);
document.addEventListener('keyup', rawKey);
mouse = new Mouse({'target': document.getElementById('canvas'),
'onMouseButton': mouseButton,
'onMouseMove': mouseMove});
canvas.resize(width, height, true);
keyboard.grab();
mouse.grab();
message("Display initialized");
if (Util.isTouchDevice) {
message("Touch device detected");
document.getElementById('button-selection').style.display = "inline";
document.getElementById('button1').onclick = function(){ selectButton(1) };
document.getElementById('button2').onclick = function(){ selectButton(2) };
document.getElementById('button4').onclick = function(){ selectButton(4) };
selectButton();
}
}
</script>
</html>