Can a script determine how it was launched?
Richard Haseltine
Posts: 100,941
Is it possible for a script to determine whether it was launched via a keyboard shortcut (such as ctrl-something)) or via some other route (menu, toolbar or content pane)? I was wondering if it would be possible to have rthe script ignore modifier keys if it was launched via a shortcut, rather than have control-freak type behaviour fire up when using ctrl/cmd in a combination.
Comments
DzApp::modifierKeyState() provides the pressed state of modifier keys that can be checked against the values from Qt::KeyboardModifier:
DzApp::isKeyDown() provides the pressed state of keys using the numeric values from Qt::Key:
DzApp::isKeySequenceDown() provides the pressed state of keys using a "PortableText" string:
You could also make use of the Sub Script sample to execute a common script in various ways; passing in arguments that control the mode of operation. One script could check modifier state and pass that along, while another doesn't.
-Rob
Right, but if a user assigns a keyboard shortcut - say ctrl-alt-shift-s - to launch Script then some modifiers will be held down (or not) as part of the shortcut, not necessarily with he intent of triggering the special behaviour. What I was wondering was if there's a way to distinguish the launch method, so that the modifiers can be ignored when the script is launched by a keyboard shortcut but can be used normally at other times.
In the next version, you'll be able to use the following example:
-Rob
Thank you Rob, I will look forward to that.