142
St
startsInvasion / files
startsInvasion / libs / node_modules / bean / support / syn / recorder.html
6.0 KB
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3<html lang="en"> 4 <head> 5 <title>Synthetic Typing Test</title> 6 <style type='text/css'> 7 body {font-family: verdana} 8 td {text-align: right} 9 td:nth-child(even) {background: #CCd} 10 #key th:nth-child(even) {background: #CCf} 11 #who th:nth-child(even) {background: #fCb} 12 </style> 13 </head> 14 <body> 15<h1>Key Recorder</h1> 16<p id='ua' tabindex='2'></p> 17<div> 18 Type 'a' 19 <input id='t_a' /> 20</div> 21<div> 22 Type [backspace] 23 <input id='t_\\b' /> - specialChars 24</div> 25<div> 26 Type [Enter] 27 <input id='t_\\r' /> - function 28</div> 29<div> 30 Type and hold [down] 31 <input id='t_down' /> - navigation 32</div> 33<div> 34 Type and hold [shift] 35 <input id='t_shift' /> - special 36</div> 37<div> 38 Type [b] 39 <input id='keyUpPrevent' /> - preventDefault keydown 40</div> 41<div> 42 Type [c] 43 <input id='keyPressPrevent' /> - preventDefault keypress 44</div> 45<div> 46 Type [tab] 47 <input id='t_\\t' /><input id='t_tab2' /> 48</div> 49<div> 50 Type [pause-break] 51 <input id='t_pause-break' /> 52</div> 53<div> 54 Type [caps] 55 <input id='t_caps' /> 56</div> 57<div> 58 Type [escape] 59 <input id='t_escape' /> 60</div> 61<div> 62 Type [num-lock] 63 <input id='t_num-lock' /> 64</div> 65<div> 66 Type [scrolllock] 67 <input id='t_scroll-lock' /> 68</div> 69<div> 70 Type [print] 71 <input id='t_print' /> 72</div> 73<div> 74 Type [f8] 75 <input id='t_f8' /> - function 76</div> 77 78<div id='leftClick'> 79 Left Click Me 80</div> 81<div id='rightClick'> 82 Right Click Me 83</div> 84<div id='dblClick'> 85 Double Click Me 86</div> 87<h3>Key Data</h3> 88<pre id='out'></pre> 89<h3>Click Data</h3> 90<pre id='clickdata'></pre> 91<script type='text/javascript' src='../../steal/steal.js'></script> 92<script type='text/javascript'> 93 steal.plugins('funcunit/syn','jquery','jquery/lang/json').start(); 94</script> 95<script type='text/javascript' id="demo-source"> 96 var gId = function(id){ 97 return document.getElementById(id) 98 }, 99 bind = function(el, ev, func){ 100 Syn.bind(gId(el.replace("\\","\\\\")), ev,func); 101 }; 102 $(function(){ 103 $("#ua").html(window.navigator.userAgent) 104 }); 105 106 var keycodes = Syn.keycodes, 107 special = { 108 backspace : "\b", 109 tab : "\t", 110 enter : "\r" 111 }, 112 convert = { 113 "\\r" : "\r", 114 "\\t" :"\t", 115 "\\b" : "\b" 116 } 117 118 isKey = function(str, val){ 119 str = convert[str] || str; 120 return keycodes[str] === String(val) 121 } 122 isChar = function(str, val){ 123 str = convert[str] || str; 124 return val && (special[str] || str).charCodeAt(0) == val 125 } 126 keyOrChar = function(str, val){ 127 return isKey(str,val) ? "key" : 128 (isChar(str, val) ? "char" : val) 129 } 130 tests= ['prevent'] 131 data= { 132 prevent :{ 133 keyup : [], 134 keydown : [], 135 keypress :[] 136 } 137 }; 138 139 binder = function(name,test){ 140 //listen for events 141 test = test || name; 142 var testData = (data[test] = {}), 143 keydown = 0, 144 keypress= 0 145 keyup = 0; 146 147 bind('t_'+name,'keydown', function(ev){ 148 testData.keydown = [ (isChar(name, ev.charCode) ? "char" : ev.charCode), 149 keyOrChar(name, ev.keyCode)]; 150 keydown++ 151 if(keydown ==2 ){ 152 //testData.repeat.push('keydown') 153 } 154 }) 155 156 bind('t_'+name,'keypress', function(ev){ 157 testData.keypress = [ (isChar(name, ev.charCode) ? "char" : ev.charCode), 158 keyOrChar(name, ev.keyCode)] 159 160 keypress++; 161 162 if(keypress ==2 ){ 163 //testData.repeat.push('keypress') 164 } 165 update(); 166 }) 167 168 bind('t_'+name,'keyup', function(ev){ 169 testData.keyup = [ (isChar(name, ev.charCode) ? "char" : ev.charCode), 170 keyOrChar(name, ev.keyCode)] 171 keyup++; 172 if(keyup ==2 ){ 173 //testData.repeat.push('keyup') 174 } 175 176 update(); 177 178 }) 179 180 181 182 $('#t_'+name).val("") 183 tests.push(test) 184 } 185 binder('a','character') 186 binder('\\b','specialChars') 187 binder('down','navigation') 188 binder('shift','special') 189 binder('\\t') 190 bind('t_tab2','keyup', function(ev){ 191 data["\\t"].keyup = [ (isChar("\\t", ev.charCode) ? "char" : ev.charCode), 192 keyOrChar("\\t", ev.keyCode)] 193 update(); 194 }) 195 binder('pause-break') 196 binder('caps') 197 binder('escape') 198 binder('num-lock') 199 binder('scroll-lock') 200 binder('print') 201 binder('f8','function') 202 binder('\\r') 203 var pd = function(ev){ 204 if(ev.preventDefault) 205 ev.preventDefault(); 206 207 ev.returnValue = false; 208 } 209 var keyDown_keyPressed = false 210 bind('keyUpPrevent','keydown', function(ev){ 211 pd(ev); 212 setTimeout(function(){ 213 if($('#keyUpPrevent').val() !== 'b'){ 214 data.prevent.keydown.push('char') 215 } 216 if(!keyDown_keyPressed){ 217 data.prevent.keydown.push('keypress') 218 } 219 update(); 220 },1000) 221 }) 222 bind('keyUpPrevent','keypress', function(ev){ 223 keyDown_keyPressed = true; 224 }) 225 226 227 var keyPress_keyUp = false 228 bind('keyPressPrevent','keypress', function(ev){ 229 pd(ev); 230 setTimeout(function(){ 231 if($('#keyPressPrevent').val() !== 'c'){ 232 data.prevent.keypress.push('char') 233 } 234 if(!keyPress_keyUp){ 235 data.prevent.keypress.push('keyup') 236 } 237 update(); 238 },1000) 239 }) 240 bind('keyPressPrevent','keyup', function(ev){ 241 keyPress_keyUp = true; 242 }) 243 244 245 var clickData = { 246 right : {}, 247 left : {}, 248 dblclick :{} 249 } 250 $.each(['right','left'], function(i, name){ 251 252 bind(name+'Click','mousedown',function(ev){ 253 clickData[name].mousedown = { 254 button: ev.button, 255 which: ev.which 256 } 257 }) 258 bind(name+'Click','mouseup',function(ev){ 259 clickData[name].mouseup = { 260 button: ev.button, 261 which: ev.which 262 } 263 setTimeout(function(){ 264 $('#clickdata').html($.toJSON(clickData)) 265 },100) 266 }) 267 bind(name+'Click','click',function(ev){ 268 clickData[name].click = { 269 button: ev.button, 270 which: ev.which 271 } 272 }) 273 bind(name+'Click','contextmenu',function(ev){ 274 clickData[name].contextmenu = { 275 button: ev.button, 276 which: ev.which 277 } 278 }) 279 280 }) 281 var dblClicks = 0 282 bind('dblClick','click',function(ev){ 283 clickData.dblclick.click = (++dblClicks) 284 }) 285 bind('dblClick','dblclick',function(ev){ 286 clickData.dblclick.dblclick = (1) 287 setTimeout(function(){ 288 $('#clickdata').html($.toJSON(clickData)) 289 },100) 290 }) 291 update = function(){ 292 var str = []; 293 $.each(tests, function(i, sub){ 294 str.push("'"+sub+ "':<br/> "+$.toJSON(data[sub])+",") 295 }) 296 297 $('#out').html(str.join("<br/>")) 298 } 299 300 301</script> 302 </body> 303</html>