Command that types a keystroke

I use obsidian mobile to take math notes. Right, now, to write for example:

2a + 24(3b + 4)

I need to press my keyboard 's equivalent of shift eight times. This is driving me mad. Thankfully Obsidian Mobile has a cute toolbar you can put convenient stuff in right? But I can’t find a way to make a command that just sends a keystroke. I could make a command right now that queries ChatGPT to summarize my note but I can’t send a goddamn plus sign. I already made templates for every key but there’s only an “Insert template” command not an “Insert specific template” command.

PLEASE HELP.

Please try this.

editor.cm.replaceSelection('+');

If you use the Templater plugin you can insert a given template at your choice of hotkey.

Another option could be to use QuickAdd plugin and build a menu of your most used math symbols and trigger that by a hotkey.

You could also adapt the mobile hotbar if you’ve got that enabled to display (and insert) your symbols by a single tap (or a swipe and a tap if on the second page).

That would be awesome, but how can I run arbitrary code like that from a command?

I fiddled with QuickAdd for what felt like ages but I couldn’t get it to make a command for me, let alone one that inserted one of my templates! Could you mention step by step how to do that?

I was aware of hotkeys but I can’t use them. I’m on a phone!

Or could you describe how to set up this mobile hotbar to do that? The mobile hotbar I saw only allows me to add commands that have already been defined.

Using Templater

The easiest is most likely to use Templater where you create a simple template with the text you want to insert, and then you do:

  • Open Settings > Templater and locate the Template Hotkeys section
  • Click the Add new hotkey for template, and choose your newly created template in the search field
  • Now this template has been added as a command, so you can trigger it using the new command: Templater: Insert <name of your template>
  • This command can be added to your mobile hotbar (without any keys assigned to it)

Using QuickAdd

I’m doing two different approaches when using QuickAdd, and the first is for simply inserting a given text somewhere.

  • Open Settings > QuickAdd
  • Under the list of choices, select Capture, enter a Name in the text field, and hit Add Choice
  • Click the lightning icon to the right of your newly created choice. This makes your new choice into a command
  • Click the gear icon, and do the following:
    • On the second line enable Capture to active file
    • Make sure the others are disabled (unless you choose to enable them)
    • Enable the Capture format
    • Enter your text in the big box

Now you can trigger a command, QuickAdd: , and it’ll insert your chosen text at the current cursor position.

Lastly, another option, which I’ve done for myself is to build a multi-menu to select various text/options/tasks, make that into a command, and then I’ve configured the swipe down action on my mobile to trigger that multi-menu.

This can be achieved through various means, where one of the options is to add a Multi choice in the QuickAdd settings, and then build your structure through adding other captures or templates or … When you’re satisfied with your menu, enable it as a command (the lightning icon) and choose that as your swipe down action.

(I’m a coder, so I’ve actually coded my multi-menu in a script, but that script is not ready for publication as of today, and is mostly suited for my personal needs… :slight_smile: )


In any case, either of the methods above defines commands which you’re able to trigger either through the Command Palette, through customising the mobile hotbar, or as a swipe down command. (On desktop you can also assign a hotkey to any command, so I’ve got a hotkey for my multi-menu so that I can use the same menu also when I’m on the desktop)

2 Likes

There’s also a community plugin called Hotkeys For Templates that lets you assign Obsidian templates to hotkeys.

Many thanks for the detailed guides! One point of conflict was setting up a hotkey as my virtual keyboard wouldn’t trigger when obsidian prompted me for a hotkey. However the quick add method works swimmingly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.