# Shortcuts and keys already assigned somewhere else?

**URL:** <https://discourse.slicer.org/t/shortcuts-and-keys-already-assigned-somewhere-else/26632>\
**Category:** Development\
**Created:** [December 7, 2022, 5:11pm UTC](https://discourse.slicer.org/t/shortcuts-and-keys-already-assigned-somewhere-else/26632 "2022-12-07T17:11:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 7, 2022, 10:57pm UTC](https://discourse.slicer.org/t/shortcuts-and-keys-already-assigned-somewhere-else/26632/4 "2022-12-07T22:57:03Z")

</div>

Most of these shortcuts work for me (except the `S` and `s`, which you broke for yourself by redefining).

Try these:

```python
shortcuts = [
  ('p', lambda: print('pressed: p')),
  ('z', lambda: print('pressed: z')),
  ('q', lambda: print('pressed: q')),
  ('f', lambda: print('pressed: f')),
  ('[', lambda: print('pressed: [')),
  (']', lambda: print('pressed: ]')),
  ('\\', lambda: print('pressed: \\')),
  (';', lambda: print('pressed: ;')),
  ('`', lambda: print('pressed: `')),
  ('~', lambda: print('pressed: ~')),
  ('Ctrl+m', lambda: print('pressed: Ctrl-m')),
  ('S', lambda: print('pressed: S')),
  ('O', lambda: print('pressed: O')),
  ('U', lambda: print('pressed: U')),
  ('D', lambda: print('pressed: D')),
]

for (shortcutKey, callback) in shortcuts:
    shortcut = qt.QShortcut(slicer.util.mainWindow())
    shortcut.setKey(qt.QKeySequence(shortcutKey))
    shortcut.connect( 'activated()', callback)

```

If you or someone else adds a shortcut with the same key sequence then effectively breaks all actions, as the shortcut will no longer emit `activated()` signal but `activatedAmbiguously()`.

Unfortunately, I don’t know an easy way to determine where each shortcut comes from where, other than search in the source code of all installed extensions for `shortcut`.

Extensions should not install any keyboard shortcut by default (without explicitly approved by the user). Also, if any shortcut is added then a meaningful `objectName` should be set, for example containing the name of the extension and module, to make it easier to detect and resolve conflicts by turning off irrelevant shortcuts.

---

_[View the full topic](https://discourse.slicer.org/t/shortcuts-and-keys-already-assigned-somewhere-else/26632)._
