محاسبه تعداد دفعات فشرده شدن کلیدهای کیبورد و کلیدهای موس (با javascript)
با استفاده از این کد می توانیم تعداد دفعات فشرده شدن کلیدهای کیبورد و کلیدهای موس را محاسبه کنیم (BPM مخفف Beats per Minute می باشد) :
کدها :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
secs2 = 0;
count = 0;
allBpm = 0;
avgBpm = 0;
bpm = 0;
ns = (navigator.appName == 'Netscape');
ie = (navigator.appName == 'Microsoft Internet Explorer');
function bpmCounter(e) {
if (ns) clearBpm = e.which;
else if (ie) clearBpm = event.button;
timeSeconds = new Date;
secs = timeSeconds.getTime();
if (count == 0) {
document.BEATSPERMINUTE.AVG.value = "";
document.BEATSPERMINUTE.NOW.value = "READY! Start NOW!";
document.BEATSPERMINUTE.HIT.value = "";
document.BEATSPERMINUTE.ACG.value = "";
document.BEATSPERMINUTE.NCG.value = "";
secs2 = secs;
count++;
}
else {
oldBpm = bpm;
bpm = (1 / ((secs - secs2) / 1000)) * 60;
bpmChg = (Math.round((bpm - oldBpm) * 10)) / 10;
count++;
allBpm = allBpm + bpm;
oldAvg = avgBpm;
avgBpm = allBpm / (count - 1);
avgChg = (Math.round((avgBpm - oldAvg) * 10)) / 10;
secs2 = secs;
if (bpmChg >= 0) { PbpmChg = "+" + bpmChg } else { PbpmChg = bpmChg }
if (avgChg >= 0) { PavgChg = "+" + avgChg } else { PavgChg = avgChg }
document.BEATSPERMINUTE.AVG.value = (Math.round(avgBpm * 100)) / 100;
document.BEATSPERMINUTE.ACG.value = PavgChg;
document.BEATSPERMINUTE.NOW.value = (Math.round(bpm * 100)) / 100;
document.BEATSPERMINUTE.NCG.value = PbpmChg;
document.BEATSPERMINUTE.HIT.value = count;
}
return true;
}
document.onkeydown = bpmCounter;
document.onmousedown = bpmCounter;
</script>
</head>
<body>
<center>
<table border=0 width=400>
<tr><td width=50% align=middle valign=top>
<form name="BEATSPERMINUTE">
<table border=0 cellpadding=3 cellspacing=0 bgcolor="#007700">
<tr><td align=middle>
<table border=0 cellpadding=3 cellspacing=0 bgcolor="#00FF00">
<tr><td align=middle>
<table border=0 cellpadding=4 cellspacing=0 bgcolor="#efefef">
<tr><td><font color="#000000"><tt>AVERAGE BPM</tt></td>
<td><input name="AVG"></td><td><input name="ACG" size="6"></td></tr>
<tr><td><font color="#000000"><tt>ONCLICK BPM</tt></td>
<td><input name="NOW"></td><td><input name="NCG" size="6"></td></tr>
<tr><td><font color="#000000"><tt>TIMING HITS</tt></td>
<td><input name="HIT"></td><td> </td></tr>
</table>
</td></tr></table>
</td></tr></table>
Click on the page to start the bpm counter<p>
Press a key or click your mouse to measure beats.<br>
You may also <input type="reset" value="RESET "> the counter.<br>
Netscape 4.x+ and MSIE 4.x+ compatible.<p>
</form>
</table>
</center>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
secs2 = 0;
count = 0;
allBpm = 0;
avgBpm = 0;
bpm = 0;
ns = (navigator.appName == 'Netscape');
ie = (navigator.appName == 'Microsoft Internet Explorer');
function bpmCounter(e) {
if (ns) clearBpm = e.which;
else if (ie) clearBpm = event.button;
timeSeconds = new Date;
secs = timeSeconds.getTime();
if (count == 0) {
document.BEATSPERMINUTE.AVG.value = "";
document.BEATSPERMINUTE.NOW.value = "READY! Start NOW!";
document.BEATSPERMINUTE.HIT.value = "";
document.BEATSPERMINUTE.ACG.value = "";
document.BEATSPERMINUTE.NCG.value = "";
secs2 = secs;
count++;
}
else {
oldBpm = bpm;
bpm = (1 / ((secs - secs2) / 1000)) * 60;
bpmChg = (Math.round((bpm - oldBpm) * 10)) / 10;
count++;
allBpm = allBpm + bpm;
oldAvg = avgBpm;
avgBpm = allBpm / (count - 1);
avgChg = (Math.round((avgBpm - oldAvg) * 10)) / 10;
secs2 = secs;
if (bpmChg >= 0) { PbpmChg = "+" + bpmChg } else { PbpmChg = bpmChg }
if (avgChg >= 0) { PavgChg = "+" + avgChg } else { PavgChg = avgChg }
document.BEATSPERMINUTE.AVG.value = (Math.round(avgBpm * 100)) / 100;
document.BEATSPERMINUTE.ACG.value = PavgChg;
document.BEATSPERMINUTE.NOW.value = (Math.round(bpm * 100)) / 100;
document.BEATSPERMINUTE.NCG.value = PbpmChg;
document.BEATSPERMINUTE.HIT.value = count;
}
return true;
}
document.onkeydown = bpmCounter;
document.onmousedown = bpmCounter;
</script>
</head>
<body>
<center>
<table border=0 width=400>
<tr><td width=50% align=middle valign=top>
<form name="BEATSPERMINUTE">
<table border=0 cellpadding=3 cellspacing=0 bgcolor="#007700">
<tr><td align=middle>
<table border=0 cellpadding=3 cellspacing=0 bgcolor="#00FF00">
<tr><td align=middle>
<table border=0 cellpadding=4 cellspacing=0 bgcolor="#efefef">
<tr><td><font color="#000000"><tt>AVERAGE BPM</tt></td>
<td><input name="AVG"></td><td><input name="ACG" size="6"></td></tr>
<tr><td><font color="#000000"><tt>ONCLICK BPM</tt></td>
<td><input name="NOW"></td><td><input name="NCG" size="6"></td></tr>
<tr><td><font color="#000000"><tt>TIMING HITS</tt></td>
<td><input name="HIT"></td><td> </td></tr>
</table>
</td></tr></table>
</td></tr></table>
Click on the page to start the bpm counter<p>
Press a key or click your mouse to measure beats.<br>
You may also <input type="reset" value="RESET "> the counter.<br>
Netscape 4.x+ and MSIE 4.x+ compatible.<p>
</form>
</table>
</center>
</body>
</html>
دسته بندی
کدهای آماده برای محاسبه گرها
نظرات 0 0 0