I’m trying to add a feature to a plugin (Obsidian Matrix) because it feels intuitive to me but is missing. The plugin has a menu that pops up to enter some text into a matrix, and you click a button once you’re done entering, it types the LaTeX for that matrix into the editor. I would like to add the option to press the Enter key as well as click the button, because that’s what I always do automatically, and it doesn’t work. However, I can’t figure out how to listen for a keypress event. Can somebody explain how or just link to an example of someone doing something similar? (I am relatively new to JS/TS and Obsidian so a simple explanation would be nice, but I can handle a complex one)
Note: I don’t want to define a hotkey, this is already happening inside a menu created during the callback event of that hotkey and I just want to bind it to the normal Enter key, so creating a hotkey would cause many conflicts
You have to listen for key UP specifically:
inputEl.addEventListener("keyup", ({key}) => {
if (key === 'Enter') {
....
Confused me at first too.
1 Like
Ah, I see! Okay, thank you and thanks for the quick response
1 Like