Skip to content

Instantly share code, notes, and snippets.

@asd142513
Created July 22, 2024 06:59
Show Gist options
  • Save asd142513/967403727f384b7eefef2477396e44a5 to your computer and use it in GitHub Desktop.
Save asd142513/967403727f384b7eefef2477396e44a5 to your computer and use it in GitHub Desktop.
Print the time interval since the last press or release
<html>
<body onmousedown="mouseDown();" onmouseup="mouseUp();">
<textarea id="box" readonly rows="24" cols="80" placeholder="unit: ms(milisecond)"></textarea>
</body>
<script type="text/javascript">
var box = document.getElementById('box');
var last = Date.now();
function mouseDown() {
cur = Date.now();
var s = 'press\t' + (cur - last) + '\n';
box.value = s + box.value;
last = cur;
}
function mouseUp() {
cur = Date.now();
var s = 'release\t' + (cur - last) + '\n';
box.value = s + box.value;
last = cur;
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment