Preventing keypress event through Atom package

I am trying to build an Atom package in which I want to prevent specific keypress events in Atom. I have the code to detect the keyboard event:

const editor = atom.workspace.getActiveTextEditor();
editorView = atom.views.getView(editor);
editorView.addEventListener(‘keydown’, function(event) {
// How to prevent the event?
});

But, I am unable to figure out how the default event can be stopped when I need it. For example, I want to prevent the default keypress event when the user presses “a” key so the editor does not add “a” in the file, how can I do that?

What is your end goal?

I want a functionality where “ESCAPE + any letter” triggers a function in my package. I know that Modifier keys should be used for such functionality. However, Modifier keys cannot be used with any letter key because some of them are already used shortcuts in Atom.

The MDN web site has good documentation about this sort of thing. Check out example 5 on that page.

Thank you, it really helped!

Sweet action. I haven’t done anything with raw event handling myself, but whenever I need to know about a web coding topic, I ask Google and look at whatever it pulls up from that web site (it’s usually one of the first results).

1 Like