-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow_keys.js
69 lines (59 loc) · 1.46 KB
/
show_keys.js
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
$(function(){
$('body').append("<div id='keylog'></div>");
var keylog = $('#keylog');
keylog.css({
'bottom':'0px',
'position':'fixed',
'right':'0px',
'width':'auto',
'zIndex':'100',
'fontSize':'30px',
'fontWeight':'bold',
'padding':'10px',
'color':'white',
'textShadow': '1px 1px 1px #aaa'});
$('body').bind('keydown',function(e){
//console.log(e, e.which, e.target , String.fromCharCode(e.which));
createKeyTag(e)
$('.key').css({
'padding':'0 10px',
'height':'45px',
'margin':'10px',
'float':'right',
'background':'#333',
'textAlign':'center',
'borderRadius':'5px'
});
});
function createKeyTag(e){
var keyText;
if ( e.which == 13 ) {
keyText = 'Enter';
} else if ( e.which == 32 ) {
keyText = 'Space';
} else if ( e.which == 190 ) {
keyText = '.';
} else if ( e.which == 16 ){
keyText = 'Shift';
} else if ( e.which == 191 ){
keyText = '?';
} else if ( e.which == 17 ){
keyText = 'Ctrl';
} else if ( e.which == 18 ){
keyText = 'Alt';
} else if ( $(e.target).attr('type') == 'password' ){
keyText = '*';
}
else {
keyText = String.fromCharCode(e.which);
}
var el = $("<div/>", {
text: keyText,
"class":"key"});
keylog.prepend(el);
el.fadeTo("slow", 0.4);
var t = setTimeout(function(){
el.fadeOut('slow',function(){$(this).remove()});
},2000);
}
});