solved - find all currently assigned shortcuts?
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: find all currently assigned shortcuts?
It will show only those commands which have shortcuts assigned. I get this output after a fresh restart and without loading many workbenches.
>>> commands = Gui.listCommands()
>>> shortcuts = [f"{c} -> {Gui.Command.get(c).getShortcut()}" for c in commands if Gui.Command.get(c).getShortcut()]
>>> shortcuts
['Draft_Arc -> A, R', 'Draft_Arc_3Points -> A, T', 'Draft_BSpline -> B, S', 'Draft_BezCurve -> B, Z', 'Draft_Circle -> C, I', 'Draft_Clone -> C, L', 'Draft_Dimension -> D, I', 'Draft_Downgrade -> D, N', 'Draft_Edit -> D, E', 'Draft_Ellipse -> E, L', 'Draft_Facebinder -> F, F', 'Draft_Fillet -> F, I', 'Draft_Hatch -> H, A', 'Draft_Join -> J, O', 'Draft_Label -> D, L', 'Draft_Line -> L, I', 'Draft_Mirror -> M, I', 'Draft_Move -> M, V', 'Draft_Offset -> O, S', 'Draft_Polygon -> P, G', 'Draft_Rectangle -> R, E', 'Draft_Rotate -> R, O', 'Draft_Scale -> S, C', 'Draft_SelectPlane -> W, P', 'Draft_SetStyle -> S, S', 'Draft_Split -> S, P', 'Draft_Stretch -> S, H', 'Draft_SubelementHighlight -> H, S', 'Draft_Text -> T, E', 'Draft_ToggleConstructionMode -> C, M', 'Draft_ToggleDisplayMode -> Shift+Space', 'Draft_ToggleGrid -> G, R', 'Draft_Trimex -> T, R', 'Draft_Upgrade -> U, P', 'Draft_Wire -> P, L', 'Sketcher_ViewSketch -> Q, P', 'Std_ActivateNextWindow -> Ctrl+Tab', 'Std_ActivatePrevWindow -> Ctrl+Shift+Backtab', 'Std_AxisCross -> A, C', 'Std_BoxElementSelection -> Shift+E', 'Std_BoxSelection -> Shift+B', 'Std_CloseActiveWindow -> Ctrl+F4', 'Std_Copy -> Ctrl+C', 'Std_Cut -> Ctrl+X', 'Std_Delete -> Del', 'Std_DlgMacroExecuteDirect -> Ctrl+F6', 'Std_Export -> Ctrl+E', 'Std_Import -> Ctrl+I', 'Std_LinkSelectLinked -> S, G', 'Std_LinkSelectLinkedFinal -> S, D', 'Std_MacroStartDebug -> F6', 'Std_MacroStepInto -> F11', 'Std_MacroStepOver -> F10', 'Std_MacroStopDebug -> Shift+F6', 'Std_Macro_2 -> , Alt+Shift+S', 'Std_MainFullscreen -> Alt+F11', 'Std_New -> Ctrl+N', 'Std_OnlineHelp -> F1', 'Std_Open -> Ctrl+O', 'Std_OrthographicCamera -> V, O', 'Std_Paste -> Ctrl+V', 'Std_PerspectiveCamera -> V, P', 'Std_Print -> Ctrl+P', 'Std_Quit -> Alt+F4', 'Std_Redo -> Ctrl+Y', 'Std_Refresh -> F5', 'Std_Save -> Ctrl+S', 'Std_SelBack -> S, B', 'Std_SelForward -> S, F', 'Std_SendToPythonConsole -> Ctrl+Shift+P', 'Std_SetAppearance -> Ctrl+D', 'Std_ToggleBreakpoint -> F9', 'Std_ToggleNavigation -> Esc', 'Std_ToggleVisibility -> Space', 'Std_TreeDrag -> T, D', 'Std_TreePreSelection -> T, 4', 'Std_TreeRecordSelection -> T, 5', 'Std_TreeSelection -> T, G', 'Std_TreeSyncPlacement -> T, 3', 'Std_TreeSyncSelection -> T, 2', 'Std_TreeSyncView -> T, 1', 'Std_Undo -> Ctrl+Z', 'Std_ViewBottom -> 5', 'Std_ViewBoxZoom -> Ctrl+B', 'Std_ViewDock -> V, D', 'Std_ViewFitAll -> V, F', 'Std_ViewFitSelection -> V, S', 'Std_ViewFront -> 1', 'Std_ViewFullscreen -> F11', 'Std_ViewHome -> Home', 'Std_ViewIsometric -> 0', 'Std_ViewLeft -> 6', 'Std_ViewRear -> 4', 'Std_ViewRight -> 3', 'Std_ViewRotateLeft -> Shift+Left', 'Std_ViewRotateRight -> Shift+Right', 'Std_ViewTop -> 2', 'Std_ViewUndock -> V, U', 'Std_ViewZoomIn -> Ctrl++', 'Std_ViewZoomOut -> Ctrl+-', 'Std_WhatsThis -> Shift+F1']
>>>
>>> commands = Gui.listCommands()
>>> shortcuts = [f"{c} -> {Gui.Command.get(c).getShortcut()}" for c in commands if Gui.Command.get(c).getShortcut()]
>>> shortcuts
['Draft_Arc -> A, R', 'Draft_Arc_3Points -> A, T', 'Draft_BSpline -> B, S', 'Draft_BezCurve -> B, Z', 'Draft_Circle -> C, I', 'Draft_Clone -> C, L', 'Draft_Dimension -> D, I', 'Draft_Downgrade -> D, N', 'Draft_Edit -> D, E', 'Draft_Ellipse -> E, L', 'Draft_Facebinder -> F, F', 'Draft_Fillet -> F, I', 'Draft_Hatch -> H, A', 'Draft_Join -> J, O', 'Draft_Label -> D, L', 'Draft_Line -> L, I', 'Draft_Mirror -> M, I', 'Draft_Move -> M, V', 'Draft_Offset -> O, S', 'Draft_Polygon -> P, G', 'Draft_Rectangle -> R, E', 'Draft_Rotate -> R, O', 'Draft_Scale -> S, C', 'Draft_SelectPlane -> W, P', 'Draft_SetStyle -> S, S', 'Draft_Split -> S, P', 'Draft_Stretch -> S, H', 'Draft_SubelementHighlight -> H, S', 'Draft_Text -> T, E', 'Draft_ToggleConstructionMode -> C, M', 'Draft_ToggleDisplayMode -> Shift+Space', 'Draft_ToggleGrid -> G, R', 'Draft_Trimex -> T, R', 'Draft_Upgrade -> U, P', 'Draft_Wire -> P, L', 'Sketcher_ViewSketch -> Q, P', 'Std_ActivateNextWindow -> Ctrl+Tab', 'Std_ActivatePrevWindow -> Ctrl+Shift+Backtab', 'Std_AxisCross -> A, C', 'Std_BoxElementSelection -> Shift+E', 'Std_BoxSelection -> Shift+B', 'Std_CloseActiveWindow -> Ctrl+F4', 'Std_Copy -> Ctrl+C', 'Std_Cut -> Ctrl+X', 'Std_Delete -> Del', 'Std_DlgMacroExecuteDirect -> Ctrl+F6', 'Std_Export -> Ctrl+E', 'Std_Import -> Ctrl+I', 'Std_LinkSelectLinked -> S, G', 'Std_LinkSelectLinkedFinal -> S, D', 'Std_MacroStartDebug -> F6', 'Std_MacroStepInto -> F11', 'Std_MacroStepOver -> F10', 'Std_MacroStopDebug -> Shift+F6', 'Std_Macro_2 -> , Alt+Shift+S', 'Std_MainFullscreen -> Alt+F11', 'Std_New -> Ctrl+N', 'Std_OnlineHelp -> F1', 'Std_Open -> Ctrl+O', 'Std_OrthographicCamera -> V, O', 'Std_Paste -> Ctrl+V', 'Std_PerspectiveCamera -> V, P', 'Std_Print -> Ctrl+P', 'Std_Quit -> Alt+F4', 'Std_Redo -> Ctrl+Y', 'Std_Refresh -> F5', 'Std_Save -> Ctrl+S', 'Std_SelBack -> S, B', 'Std_SelForward -> S, F', 'Std_SendToPythonConsole -> Ctrl+Shift+P', 'Std_SetAppearance -> Ctrl+D', 'Std_ToggleBreakpoint -> F9', 'Std_ToggleNavigation -> Esc', 'Std_ToggleVisibility -> Space', 'Std_TreeDrag -> T, D', 'Std_TreePreSelection -> T, 4', 'Std_TreeRecordSelection -> T, 5', 'Std_TreeSelection -> T, G', 'Std_TreeSyncPlacement -> T, 3', 'Std_TreeSyncSelection -> T, 2', 'Std_TreeSyncView -> T, 1', 'Std_Undo -> Ctrl+Z', 'Std_ViewBottom -> 5', 'Std_ViewBoxZoom -> Ctrl+B', 'Std_ViewDock -> V, D', 'Std_ViewFitAll -> V, F', 'Std_ViewFitSelection -> V, S', 'Std_ViewFront -> 1', 'Std_ViewFullscreen -> F11', 'Std_ViewHome -> Home', 'Std_ViewIsometric -> 0', 'Std_ViewLeft -> 6', 'Std_ViewRear -> 4', 'Std_ViewRight -> 3', 'Std_ViewRotateLeft -> Shift+Left', 'Std_ViewRotateRight -> Shift+Right', 'Std_ViewTop -> 2', 'Std_ViewUndock -> V, U', 'Std_ViewZoomIn -> Ctrl++', 'Std_ViewZoomOut -> Ctrl+-', 'Std_WhatsThis -> Shift+F1']
>>>
Re: find all currently assigned shortcuts?
Thank you !TheMarkster wrote: ↑Fri Jan 28, 2022 7:19 pm It will show only those commands which have shortcuts assigned...
That does indeed begin to look like what I was after
I will try it tomorrow
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: find all currently assigned shortcuts?
I can break it down a bit further.
commands = Gui.listCommands() creates a new list of strings called commands which contains all the commands available, example: 'Std_AxisCross' which is the command for toggling the axis cross.
shortcuts = [f"{c} -> {Gui.Command.get(c).getShortcut()}" for c in commands if Gui.Command.get(c).getShortcut()] is a bit more complicated. It create a new list named shortcuts. f"{c}" is a formatted string in python. Here c is the command, e.g. 'Std_AxisCross'. The -> bit is just " -> " added to that string, so you would have Std_AxisCross -> to which gets added the shortcut in {Gui.Command.get(c).getShortcut()}. The for c in commands means to do this for each command in commands, which we refer to as c. Then finally "if Gui.Command.get(c).getShortcut()" means we only want those that have a shortcut.
commands = Gui.listCommands() creates a new list of strings called commands which contains all the commands available, example: 'Std_AxisCross' which is the command for toggling the axis cross.
shortcuts = [f"{c} -> {Gui.Command.get(c).getShortcut()}" for c in commands if Gui.Command.get(c).getShortcut()] is a bit more complicated. It create a new list named shortcuts. f"{c}" is a formatted string in python. Here c is the command, e.g. 'Std_AxisCross'. The -> bit is just " -> " added to that string, so you would have Std_AxisCross -> to which gets added the shortcut in {Gui.Command.get(c).getShortcut()}. The for c in commands means to do this for each command in commands, which we refer to as c. Then finally "if Gui.Command.get(c).getShortcut()" means we only want those that have a shortcut.
Re: find all currently assigned shortcuts?
now that you mention it, the confusing picture is clearer
thank you
Re: find all currently assigned shortcuts?
Thank you Mark,TheMarkster wrote: ↑Fri Jan 28, 2022 8:15 pm ...
commands = Gui.listCommands() creates a new list of strings called commands which contains all the commands available, example: 'Std_AxisCross' which is the command for toggling the axis cross.
tried it today and it works exactly as advertised/
The output is long, single line string which I ended up copying and pasting into word document to format it into something more readable.
It has helped me with what I was trying to do!
Re: find all currently assigned shortcuts?
Not a judgment, just notice that Mark's method only gives you shortcuts assigned to commands.
Re: find all currently assigned shortcuts?
Oh I know, but it's probably my ignorance in not asking precise enough question in the first place
and getting the answer that suited my needs by lack rather than judgement
i.e.
When I tried:Std_3DViewPreselection -> V, Q',
'Std_ActivateNextWindow -> Ctrl+Tab',
'Std_ActivatePrevWindow -> Ctrl+Shift+Backtab',
'Std_AxisCross -> A, C',
'Std_BoxElementSelection -> Ctrl+Shift+E',
'Std_BoxSelection -> Shift+B',
'Std_ClipPlaneDragger -> C, D',
'Std_CloseActiveWindow -> Ctrl+W',
'Std_CmdHistory -> R, R',
'Std_Copy -> Ctrl+C',
'Std_Cut -> Ctrl+X',
'Std_Delete -> Del',
etc,
etc,
Code: Select all
from PySide import QtGui
[act.shortcut().toString() for act in Gui.getMainWindow().findChildren(QtGui.QAction) if not act.shortcut().isEmpty()]
[act.key().toString() for act in Gui.getMainWindow().findChildren(QtGui.QShortcut) if not act.key().isEmpty()]
i.e.
Both answers are useful and especially when used in combination?'Alt+F4',
'W, 1',
'W, 2',
'W, 3',
'W, 4',
'W, 5',
'W, 6',
'W, 7',
'W, 8',
'W, 9',
'F1',
'Ctrl+N',
'Ctrl+O
etc,
etc,
So, I am grateful to all contributors and can only apologise for my sloppiness
Re: find all currently assigned shortcuts?
bambuko wrote: ↑Sat Jan 29, 2022 4:03 pm When I tried:I got a list of shortcuts but without info about what are they assigned toCode: Select all
from PySide import QtGui [act.shortcut().toString() for act in Gui.getMainWindow().findChildren(QtGui.QAction) if not act.shortcut().isEmpty()] [act.key().toString() for act in Gui.getMainWindow().findChildren(QtGui.QShortcut) if not act.key().isEmpty()]
Code: Select all
from PySide import QtGui
[f"{act.whatsThis()} => {act.shortcut().toString()}" for act in Gui.getMainWindow().findChildren(QtGui.QAction) if not act.shortcut().isEmpty()]
[f"{act.whatsThis()} => {act.key().toString()}" for act in Gui.getMainWindow().findChildren(QtGui.QShortcut) if not act.key().isEmpty()]
Re: find all currently assigned shortcuts?
this is brain damage level for me
I have run the command, copied output into word and I am formatting it to compare.
It's like a foreign language to me, this Python thing I never cease to be amazed by you guys...