OLibJ Keyhook API Reference

Table Contents
Hooking Keyboard with callback function
Hooking keyboard return: integer OJ.Keyhook.catches API는 키보드 입력을 hooking하여 callback 함수를 이용하여 원하는 행동을 할 수 있도록 한다. 아래 예제를 참조 하도록 한다. callback 함수를 작성할 경우, 첫번째 인자에 입력된 key가 전달이 되며, key 값이 null로 전달될 경우에는 callback 함수를 초기화 시켜 주어야 한다. callback 함수를 지정하지 않았을 경우에는 기본 동작으로 입력된 키가 alert으로 동작한다. OJ.Keyhook.catches ()
value of key
<script type="text/javascript"> var presskey = ''; function keyhook_callback (c) { // 키값이 null이면 callback function을 초기화 한다. if ( c === null || c === '\r' || c === '\n' ) { if ( presskey.length > 0 ) alert (presskey); presskey = ''; document.getElementById ('kval') .innerHTML = 'value of key'; return; } if ( presskey.length == 0 && c.match (/[^0-9]/) ) { if ( c !== ' ' ) // space는 통과 시키자!! alert (c); } else { if ( c !== ' ' ) // space는 통과 시키자!! return; presskey += c; document.getElementById ('kval') .innerHTML = presskey; } return; } OJ.Keyhook.catches (keyhook_callback); </script>