기본적으로 브라우저에서 AccessKey를 이용하여 단축키를 지정할 수 있다.


<a href="http://mooki83.da.to/" accesskey="1">


링크를 바로 지정하거나 (ALT + 1)


<input type="submit" accesskey="0">


submit 버튼을 누르는 단축 버튼으로도 사용한다. (ALT + 0)



하지만 나는 좀 더 파워풀하게 단축키를 지정하고 싶다.

자바스크립트를 이용하여 단축키를 설정하는 방법


Handling Keyboard Shortcuts in Javascript (추천)

http://www.openjs.com/scripts/events/keyboard_shortcuts/


jQuery Keyboard Hooker Plugin

http://code.google.com/p/snippets-4-all/



참고

KeyCode.js

http://jonathan.tang.name/code/js_keycode



Handling Keyboard Shortcuts in Javascript에서 사용하는 shortcut.js 사용법도 간단하고 괜찮은 듯..


지정하기 (Alt + 1)

shortcut.add("Alt+1", function(){
    location.href = "http://mooki83.da.to";
}, {
    'type' : 'keydown',
 
    // EVNET TYPE - 'keydown', 'keyup', 'keypress'
    // 기본값은 'keydown'
 
    'disable_in_input' : true,
    // input, textarea에 포커스되어있을 경우 작동하지 않도록 설정
    // 기본값은 false
 
    'propagate' : true,
    // Allow the event to propagate?
    // 기본값은 false
 
    'target' : document,
    // 타겟 Element 지정
    // 기본값은 document
 
    'keycode' : '65',
    // 키코드를 직접 지정
})


해제하기

shortcut.remove("Alt+1");




shortcut.js


Posted by Mooki
,