Phiên bản đầy đủ: jsB@nk » Ứng dụng » Theo dõi bàn phím
URL: https://www.javascriptbank.com/arrowkeys-detecting-the-shiftctrlalt-keys.html
Hiệu ứng có thể dùng để theo dõi xem người lướt web có sử dụng các phím Ctrl, Shift hay không.
Phiên bản đầy đủ: jsB@nk » Ứng dụng » Theo dõi bàn phím
URL: https://www.javascriptbank.com/arrowkeys-detecting-the-shiftctrlalt-keys.html
<script type="text/javascript" src="x_core.js"></script><script type="text/javascript" src="x_event.js"></script><script type="text/javascript">var shiftMode = false; // if true the shift key is downvar ctrlMode = false; // if true the ctrl key is downvar altMode = false; // if true the alt key is down function winOnLoad(){ log(); xAddEventListener(document, 'keydown', docOnKeydown, false); xAddEventListener(document, 'keyup', docOnKeyup, false); xAddEventListener(document, 'keypress', docOnKeypress, false);}function docOnKeydown(ev){ var e = new xEvent(ev); switch (e.keyCode) { case 16: shiftMode = true; log('shift down'); break; case 17: ctrlMode = true; log('ctrl down'); break; case 18: altMode = true; // not supported by Opera and I agree log('alt down'); break; }}function docOnKeyup(ev){ var e = new xEvent(ev); switch (e.keyCode) { case 16: shiftMode = false; log('shift up'); break; case 17: ctrlMode = false; log('ctrl up'); break; case 18: altMode = false; // not supported by Opera and I agree log('alt up'); break; }}function docOnKeypress(ev){ var e = new xEvent(ev); if (e.keyCode == 13) { if (shiftMode) log('shift+enter'); if (ctrlMode) log('ctrl+enter'); if (altMode) log('alt+enter'); }}function log(s){ var ta = xGetElementById('log'); if (s) ta.value += s + '\n'; else ta.value = '';}</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<form onsubmit="return false"><textarea id="log" rows="20" cols="20"></textarea><br><input type="reset" value="Clear Textarea"></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
http://javascriptbank.com/javascript/utility/x_core.jshttp://javascriptbank.com/javascript/utility/x_event.js