Skip to content

How to disable the default keyboard keybinds? #2418

Answered by pearcetm
geoff-harper asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a code snippet from one of my projects that uses the approach @msalsbery mentioned (I'd forgotten where to look in my own code, having solved this quite a while ago now).

    // suppress default OSD keydown handling for a subset of keys
    viewer.addHandler('canvas-key',event=>{
        if(['q', 'w', 'e', 'r', 'a', 's', 'd', 'f'].includes(event.originalEvent.key)){
            event.preventDefaultAction = true;
        }
    });

I believe you should still receive the event with any other handlers that are bound. If you have trouble, I'd be happy to look into it further.

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@geoff-harper
Comment options

@pearcetm
Comment options

Answer selected by geoff-harper
Comment options

You must be logged in to vote
1 reply
@msalsbery
Comment options

Comment options

You must be logged in to vote
2 replies
@geoff-harper
Comment options

@pearcetm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants