Skip to content

Keyboard Shortcuts

Hiromichi Yokoyama edited this page Aug 4, 2026 · 3 revisions

Keyboard Shortcuts Reference

This page is a complete reference of every keyboard shortcut wired into MoleditPy's main window (ui/main_window_init.py) and the 2D editor's keyPressEvent handler (ui/molecular_scene_handler.py, key maps defined in ui/molecule_scene.py). It does not cover the Shortcut-* pages, which are about creating desktop launcher icons (.exe/file-association shortcuts), a completely different topic.

Plugins can also register their own shortcuts via context.add_menu_action(path, callback, shortcut=...) (see ui/plugin_menu_manager.py); those vary by which plugins you have installed and are not listed here — check Plugin menu items for an assigned shortcut shown next to the entry.


1. 2D Editor — Context-Sensitive Keys

These are handled directly by the 2D scene's keyPressEvent and only fire when the mouse cursor is over the 2D canvas (or, for selection-based ones, when items are selected). Most of them act on whatever atom/bond is under the mouse cursor, falling back to the current selection.

1.1 Change element under cursor / switch atom-draw mode

If the cursor is over an atom, pressing one of these keys changes that atom's element in place. If the cursor is over empty canvas, the same key switches the current drawing mode to "place this element."

Key Element
C Carbon
N Nitrogen
O Oxygen
S Sulfur
F Fluorine
B Boron
I Iodine
H Hydrogen
P Phosphorus
Shift+C Chlorine (Cl)
Shift+B Bromine (Br)
Shift+S Silicon (Si)

1.2 Bond order / stereo under cursor or on selected bond(s)

If one or more bonds are selected, or the cursor hovers a bond, these change its order/stereo. Bonds are matched by looking up (atom1_id, atom2_id) in the data model in either direction.

Key Effect
1 Set bond to single (clears stereo)
2 Set bond to double (clears stereo)
3 Set bond to triple (clears stereo)
W Set bond to Wedge stereo (pressing again on an existing wedge flips its direction by swapping the begin/end atom)
D Set bond to Dash stereo (pressing again on an existing dash flips its direction the same way)
Z On a hovered double bond only: set Z (cis) configuration
E On a hovered double bond only: set E (trans) configuration

If no bond is targeted, 1/2/3 fall through to §1.3 (add a new atom+bond from the current atom).

1.3 Add atom/bond from the current atom

If the cursor is over an atom (or exactly one atom is selected) and no bond was targeted by §1.2, 1/2/3 create a new bond of that order from that atom: to an existing nearby atom if one is found within the snap tolerance (bond_snapping_distance_2d setting, default 14.0 px), otherwise a brand-new carbon atom is created at the calculated position and bonded. Placement direction alternates (clockwise/counter-clockwise) between successive single/double-bond placements so chains zig-zag naturally; this alternation is skipped for triple bonds.

1.4 Charge / radical on hovered or selected atom(s)

Key Effect
+ Increase formal charge by 1
- Decrease formal charge by 1
. (period) Cycle radical electron count 0 → 1 → 2 → 0

Applies to every selected AtomItem if there is a selection, otherwise to the atom under the cursor.

1.5 Benzene template one-shot placement

Key Effect
4 If the cursor is over an existing atom or bond: places (and fuses) a benzene ring against it in one shot, using the same live-preview geometry as dragging the benzene template. If the cursor is over empty canvas: switches the current mode to the benzene-template placement mode (same as clicking the benzene button on the template toolbar).

1.6 Delete / cancel

Key Effect
Delete / Backspace If a bond is currently being drawn (a temporary rubber-band line is active), cancels that in-progress drag. Otherwise deletes every selected atom/bond, plus the item under the cursor if any. If this empties the canvas, the scene is fully cleared and reinitialized.

1.7 Select mode / Select All

Key Effect
Space If not already in Select mode: switches to Select mode. If already in Select mode: selects all atoms/bonds (Edit ▸ Select All).

1.8 Global mode switch (fallback)

If none of the above consume the key, and no modifier other than Shift is held, an element key (§1.1) or a bond-order key switches the current drawing mode for subsequent clicks (rather than acting on something under the cursor) — this is how 1/2/3 behave when nothing is selected and the cursor isn't over an atom.

Internally there is also a raw key→bond-mode map (key_to_bond_mode_map in ui/molecule_scene.py) that additionally defines 4 → Wedge and 5 → Dash mode-switch entries. The 4 entry is unreachable in practice (it's intercepted earlier by the benzene one-shot handler in §1.5), but 5 is live: with no modifier held and no bond/atom target consuming the key first, pressing 5 switches the current drawing mode to Dash-bond placement. This is not exposed on any toolbar button shortcut label — it only works as a bare keypress.

1.9 Alt key — suppress template auto-fusing

Holding Alt while placing a ring template (or moving the live preview) suppresses the automatic double-bond/fusion adjustment logic (template_fusing_enabled_2d setting) that normally kicks in when a template preview is dropped over existing bonds. This is a modifier held during drag, not a standalone shortcut.


2. Menu Shortcuts (global, defined in ui/main_window_init.py)

These are standard QAction shortcuts, active anywhere in the main window (not scoped to the 2D canvas).

File menu

Shortcut Action
Ctrl+N New
Ctrl+O Open Project...
Ctrl+S Save Project
Ctrl+Shift+S Save Project As...
Ctrl+Q Quit

(Import/Export submenu items — MOL/SDF, SMILES, InChI, 3D MOL/XYZ, PME Raw, PNG/SVG, STL, OBJ/MTL — have no keyboard shortcut; they must be reached through the menu.)

Edit menu

Shortcut Action
Ctrl+Z (platform standard Undo) Undo
Platform standard Redo (Ctrl+Y on Windows, Ctrl+Shift+Z on macOS/Linux) Redo
Ctrl+X (platform standard Cut) Cut
Ctrl+C (platform standard Copy) Copy
Ctrl+V (platform standard Paste) Paste
Ctrl+R Rotate 2D... (opens the 2D-rotation dialog)
Ctrl+J Clean Up 2D (Edit ▸ Clean Up 2D, RDKit Compute2DCoords-based re-layout)
Ctrl+K Convert 2D to 3D
Ctrl+L Optimize 3D
Ctrl+A (platform standard SelectAll) Select All
Ctrl+Shift+C Clear All

Add Hydrogens and Remove Hydrogens have no shortcut.

Note: the shortcut for the 3D camera reset lives in the View menu as Ctrl+Shift+R (see below), not Ctrl+RCtrl+R is "Rotate 2D...". Some older MoleditPy documentation (pre-4.x) lists Ctrl+R as "Reset 3D View"; that has since moved to Ctrl+Shift+R.

View menu

Shortcut Action
Platform standard ZoomIn (typically Ctrl++) Zoom In — scales the 2D view by ×1.2
Platform standard ZoomOut (typically Ctrl+-) Zoom Out — scales the 2D view by ÷1.2
Ctrl+0 Reset Zoom — resets the 2D view transform to a fixed 0.75 scale
Ctrl+9 Fit to View — fits all visible 2D scene items into the viewport (falls back to Reset Zoom if the scene is empty)
Ctrl+Shift+R Reset 3D View — calls plotter.reset_camera() on the 3D view
Ctrl+1 Panel Layout: Equal Panels (50:50)
Ctrl+2 Panel Layout: 2D Focus (70:30)
Ctrl+3 Panel Layout: 3D Focus (30:70)
Ctrl+H Toggle 2D Panel visibility

Redraw 3D Molecule, the chiral-label toggle, the atom-info-display submenu (Show Index / Original ID / XYZ Index / Coordinates / Element Symbol), and the 0-based/1-based index-base toggle have no shortcuts.

Analysis / 3D Edit / Settings / Help menus

None of the Analysis menu items (Show Analysis...), 3D Edit menu items (Translation..., Move Selected Atoms..., Move Group..., Align to ▸ Axis/Plane, Mirror..., Planarize..., Adjust Bond Length/Angle/Dihedral Angle..., Constrained Optimization...), Plugin ▸ Plugin Manager..., Settings menu items, or Help menu items (About, GitHub, GitHub Wiki, User Manual) have a keyboard shortcut assigned — they are menu-only. Reset All Settings is also menu-only.


3. 3D View Mouse/Modifier Controls

Not strictly "keyboard shortcuts," but documented here since they're the 3D-view equivalent and are frequently confused with the above:

Input Effect
Left-drag Rotate the 3D view
Mouse wheel / Ctrl+wheel Zoom
Middle-drag, or Shift+Left-drag Pan
Toolbar 3D Select toggle Enter atom-picking/measurement mode (2/3/4-atom selections show distance/angle/dihedral); no keyboard shortcut, toolbar button only
Toolbar 3D Drag toggle, or hold Alt Enter (or temporarily enter, while held) 3D atom-drag mode: click-drag an atom in the 3D view to move it and everything connected to it

4. Practical notes

  • Shortcuts are consumed in a strict order inside keyPressEvent: benzene one-shot (4) → radical (.) → charge (+/-) → atom-symbol change → bond-order/stereo change → Z/E on hover → new-atom-from-bond-order → delete/cancel → Space → global mode switch. A key can be "eaten" by an earlier rule even if you expect a later one — e.g. if a bond is selected, 1/2/3 always retarget that bond's order rather than adding a new atom.
  • All 2D-editor key handling requires the 2D panel to be in an editable state (ui_manager.is_2d_editable); once you enter 3D-viewer-only mode (via Import ▸ 3D MOL/SDF or 3D XYZ, which clears the 2D editor), these keys stop responding until you start a new 2D structure.
  • Standard-key shortcuts (Undo, Redo, Cut, Copy, Paste, SelectAll, ZoomIn, ZoomOut) resolve through Qt's QKeySequence.StandardKey, so their exact key combination follows the OS convention (e.g. Cmd instead of Ctrl on macOS) rather than being hardcoded.

5. See also

Clone this wiki locally