Javascript 단축키 생성: 두 판 사이의 차이

IT위키
태그: 수동 되돌리기 시각 편집
 
6번째 줄: 6번째 줄:
   
   
  document.onkeyup = function(e) {
  document.onkeyup = function(e) {
     if (e.which == 117)  isCtrl = false;
     if (e.which == 17)  isCtrl = false;
     if (e.which == 18)  isAlt = false;
     if (e.which == 18)  isAlt = false;
   
   

2024년 2월 23일 (금) 18:08 기준 최신판

Javascript로 웹 페이지에서 단축키 사용 가능하게 만들기

예제[편집 | 원본 편집]

ex) `Ctrl + Alt + c` 을 눌렀을 때 이벤트 생성

var isCtrl, isAlt;  // ctrl. Alt 눌림 여부 확인

document.onkeyup = function(e) {
    if (e.which == 17)  isCtrl = false;
    if (e.which == 18)  isAlt = false;

}

document.onkeydown = function(e) {
    if (e.which == 17)  isCtrl = true;
    if (e.which == 18)  isAlt = true;

    console.log(e.which , isCtrl, isAlt)
    if (e.which == 67 && isCtrl == true && isAlt == true) {  // Ctrl + Alt + c
        console.log("ctrl + alt + c");
		return false;
   }
}

같이 보기[편집 | 원본 편집]