solved - find all currently assigned shortcuts?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
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!
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: find all currently assigned shortcuts?

Post by TheMarkster »

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']
>>>
User avatar
bambuko
Veteran
Posts: 2185
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: find all currently assigned shortcuts?

Post by bambuko »

TheMarkster wrote: Fri Jan 28, 2022 7:19 pm It will show only those commands which have shortcuts assigned...
Thank you !
That does indeed begin to look like what I was after👍
I will try it tomorrow
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: find all currently assigned shortcuts?

Post by TheMarkster »

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.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: find all currently assigned shortcuts?

Post by openBrain »

bambuko wrote: Fri Jan 28, 2022 5:21 pm just out of curiosity (and for my education, please) what is the difference between (for example) 'Z and Z' ???
You misinterpreted the result. ;)
It gives you a list of all shortcuts, each enclosed in between single quotes.
User avatar
bambuko
Veteran
Posts: 2185
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: find all currently assigned shortcuts?

Post by bambuko »

openBrain wrote: Sat Jan 29, 2022 6:44 am ... each enclosed in between single quotes.
:idea: now that you mention it, the confusing picture is clearer :lol:
thank you
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
bambuko
Veteran
Posts: 2185
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: find all currently assigned shortcuts?

Post by bambuko »

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.
Thank you Mark,
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!
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: find all currently assigned shortcuts?

Post by openBrain »

bambuko wrote: Sat Jan 29, 2022 11:02 am Thank you Mark,
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!
Not a judgment, just notice that Mark's method only gives you shortcuts assigned to commands. ;)
User avatar
bambuko
Veteran
Posts: 2185
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: find all currently assigned shortcuts?

Post by bambuko »

openBrain wrote: Sat Jan 29, 2022 2:32 pm ...Not a judgment, just notice that Mark's method only gives you shortcuts assigned to commands. ;)
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 :lol:
i.e.
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,
When I tried:

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 got a list of shortcuts but without info about what are they assigned to (no criticism - it was what I apparently asked for :oops:)

i.e.
'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,
Both answers are useful and especially when used in combination?
So, I am grateful to all contributors and can only apologise for my sloppiness
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: find all currently assigned shortcuts?

Post by openBrain »

bambuko wrote: Sat Jan 29, 2022 4:03 pm When I tried:

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 got a list of shortcuts but without info about what are they assigned to

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()]
:)
User avatar
bambuko
Veteran
Posts: 2185
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: find all currently assigned shortcuts?

Post by bambuko »

openBrain wrote: Mon Jan 31, 2022 8:44 pm ... :)
this is brain damage level for me :? :lol:
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 :mrgreen: I never cease to be amazed by you guys...
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
Post Reply