簡體   English   中英

如何覆蓋Mac OS快捷方式?

[英]How to override Mac OS shortcuts?

我正在開發一個web應用程序,它監聽keydown事件的組合,例如CTRL + B.我的問題是在mac上偵聽CTRL + ArrowKey。 這在PC上工作正常,但在Mac上這是在桌面之間切換的快捷方式,因此第二個keydown事件(箭頭鍵)不會觸發。 有沒有辦法覆蓋mac os CTRL +箭頭快捷方式,或者在Mac上的javascript中監聽這個組合?

document.onkeydown = listenForSecondKey;

function listenForSecondKey(event){
    console.log(event.key);
    event.preventDefault ? event.preventDefault() : (event.returnValue=false);
    if ((holdDown1 == true)&&(holdDown2 == true)){
        if (event.which == push){
            document.removeEventListener("keydown", keyGoingDown);
            if (postcondition){
                showPostCondition();
            }
            else{
                killTable();
                correctAnswerSubmitted(); 
            }
        }
        else{
            killTable();
            incorrectAnswerSubmitted();
        }
        holdDown1 = false;
        holdDown2 = false;
    }
}


function keyGoingDown(event){
    event.preventDefault ? event.preventDefault() : (event.returnValue=false);

        if (event.key == hold1) {
            holdDown1 = true;
        }
        else if (event.key == hold2){
            if (holdDown1 == true){
                    holdDown2 = true;
                }
        }
    else{
        //Wrong, but also shouldn't detect push down 
    }

}

document.addEventListener("keydown", keyGoingDown);

我想這可能會給出一個想法。

document.addEventListener('keydown', (e) => {

    if ( e.key === 'ArrowLeft' ) {
        e.preventDefault() // Stop other operations
    }

})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM