-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvirtualKeyboard.html
More file actions
205 lines (200 loc) · 6.23 KB
/
virtualKeyboard.html
File metadata and controls
205 lines (200 loc) · 6.23 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="Description" content=""/>
<link rel="shortcut icon" href=""/>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--
<link href="css/style.css" rel="stylesheet"/>
-->
<link href="css/jquery.terminal.min.css" rel="stylesheet"/>
<link href="css/jquery-ui.min.css" rel="stylesheet"/>
<link href="keyboard/keyboard.css" rel="stylesheet"/>
<meta name="robots" content="noindex"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
margin: 0;
padding: 0;
}
#keyboard-wrapper {
position: relative;
}
#keyboard-wrapper textarea {
position: absolute;
clip: rect(0,0,0,0);
}
.ui-keyboard {
border-width: 1px 0 0 0;
border-radius: 0;
}
button {
outline: none;
}
#keyboard-wrapper .ui-keyboard {
top: 0 !important;
margin-top: -1px; /* fix 1px border */
}
.terminal {
height: calc(100vh - var(--keyboard-height));
box-sizing: border-box;
}
.ui-keyboard-input {
display: none;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.mousewheel-min.js"></script>
<script src="js/jquery.terminal.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="keyboard/jquery.keyboard.js"></script>
<script>
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| 'onmsgesturechange' in window; // works on ie10
}
// event functions taken from tests
function keydown(options) {
var settings = $.extend({}, {
ctrl: false, alt: false, shift: false
}, options);
var e = $.Event("keydown");
e.ctrlKey = settings.ctrl;
e.altKey = settings.alt;
e.shiftKey = settings.shift;
if (typeof settings.which === 'undefined') {
which = settings.key.toUpperCase().charCodeAt(0);
}
e.key = settings.key;
e.which = e.keyCode = settings.which;
return e;
}
function keypress(key) {
var e = $.Event("keypress");
e.key = key;
e.which = e.keyCode = 0;
return e;
}
function shortcut(options) {
var settings = $.extend({}, {
ctrl: false, alt: false, shift: false, skip_keypress: false
}, options);
var doc = $(document.documentElement || window);
if (typeof settings.which === 'undefined') {
settings.which = settings.key.toUpperCase().charCodeAt(0);
}
doc.trigger(keydown(settings));
if (!settings.skip_keypress) {
doc.trigger(keypress(settings.key));
}
doc.trigger($.Event("keyup"));
}
$(function() {
$.keyboard.keyaction.pageup = function() {
term.scroll(-10);
};
$.keyboard.keyaction.pagedown = function() {
term.scroll(10);
};
$.keyboard.keyaction.foo = function() {
console.log('foo');
};
var keyboard = $('textarea').keyboard({
layout: 'custom',
customLayout: {
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
'{tab} q w e r t y u i o p [ ] \\',
'a s d f g h j k l ; \' {enter}',
'{shift} z x c v b n m , . / {shift} {pageup}',
'{sp:2} {alt} {space} {sp:1} {left} {right} {pagedown}'
],
'shift': [
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
'{tab} Q W E R T Y U I O P { } |',
'A S D F G H J K L : " {enter}',
'{shift} Z X C V B N M < > ? {shift}',
'{space} {left} {right}'
]
},
display: { 'pageup': 'pgUp', 'pagedown': 'pgDown' },
usePreview: false,
alwaysOpen: true,
stayOpen: true,
appendTo: '#keyboard-wrapper'
}).getkeyboard().reveal();
// there is no other easy way to make cursor working with keyboard
// the result of this is that textarea can have garbage
(function(insertText) {
keyboard.insertText = function(text) {
if (text === '\x08') {
shortcut({witch: 8, key: 'backspace', skip_keypress: true});
} else {
term.insert(text);
}
//return insertText.apply(keyboard, [].slice.call(arguments));
};
})(keyboard.insertText);
// proper use of API
$.extend($.keyboard.keyaction, {
enter: function(base, el, e) {
shortcut({which: 13, key: 'enter'});
},
tab: function(base, el, e) {
shortcut({which: 9, key: 'tab'});
},
left: (function(left) {
return function(base, el, e) {
// match terminal postion with
var cmd = term.cmd();
cmd.position(-1, true);
left.apply(this, [].slice.call(arguments));
};
})($.keyboard.keyaction.left),
right: (function(right) {
return function(base, el, e) {
var cmd = term.cmd();
cmd.position(1, true);
right.apply(this, [].slice.call(arguments));
};
})($.keyboard.keyaction.right)
});
var intepreter = {
toggle: function() {
if (this.frozen()) {
this.freeze(false);
} else {
this.freeze(true);
}
},
foo: function() {
this.echo('bar');
},
help: function() {
this.echo('Avaiable commands: ' + Object.keys(intepreter).join(', '));
}
};
var term = $('#term').terminal(intepreter, {
name: 'virtual',
greetings: 'Virtual Keyboard Demo',
completion: true
});
//term.freeze(true);
document.body.style.setProperty('--keyboard-height', $('#keyboard-wrapper').height() + 'px');
});
</script>
</head>
<body>
<div id="term"></div>
<div id="keyboard-wrapper">
<textarea></textarea>
</div>
<script defer src="https://umami.jcubic.pl/script.js"
data-website-id="bb1c5851-93fe-4fce-8209-944c25b8f7be"></script>
<script src="https://js-de.sentry-cdn.com/c6868ced9c228b7da5e50196c0ab2f14.min.js" crossorigin="anonymous"></script>
</body>
</html>