Detecting keyboard modifier status for Tool (Button) script

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Detecting keyboard modifier status for Tool (Button) script

Post by SimplSam »

Hi,

I have created a Tool (Button) script, and I would like to determine if the Control (CTRL) key was depressed at the time when the script was invoked (or during the scripts execution).

Essentially it would extend the usefulness / functionality of the Tools (Button) feature, allowing the script to execute normally for a normal button click, and execute with different behavior if certain modifier keys were used.

I understand that the normal mechanism to detect user interaction would be to use Event Driven processing (keyEvent, mouseEvent) to determine modifier key status, but the Tool (Button) invocation does not appear to register as a handler for those events.

I was hoping that there was some Global register that I could peek at to get the modifier keys status.

Thanks
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
synthsin75
Posts: 9972
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by synthsin75 »

No, button scripts have no way to access keyevents.
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by Breinmeester »

The Edit Keyboard Shortcuts dialog allows you to set modifier keys for tools. In your case you would have to have different tools for different key combinations, but that would take up too much space in the Tool window. If we could also set shortcuts for the Scripts menu, it wouldn't be a problem.
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by SimplSam »

Yeah - I was trying to keep it simple. Not go adding multiple buttons or additional keyboard shortcuts.

The real idea was to have the Button function normally to do something quick and simple, but then have the option to pull up a configuration dialog and change the buttons default behavior (preferences) - if the user pressed CTRL and Button (for example).

We can but dream!
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
synthsin75
Posts: 9972
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by synthsin75 »

I have one button script that I ended up using frame zero and the selected layer visibility (eyes) disabled to evoke an options menu when pressed. Otherwise it does its usual function.
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by SimplSam »

synthsin75 wrote:I have one button script that I ended up using frame zero and the selected layer visibility (eyes) disabled to evoke an options menu when pressed.
Hmmm not a bad approach. I am beginning to like that idea.

I was also thinking of a 'dirty flag' file, on the File System (but that's inconvenient), or if the button was invoked on an empty unsaved document.

You have given me food for thought.

Cheers
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
synthsin75
Posts: 9972
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Detecting keyboard modifier status for Tool (Button) scr

Post by synthsin75 »

Yeah, on that particular button script I went a bit crazy with the idea of context sensitivity. If you press it in one circumstance you get an option menu, in others it creates layers, changes selected layer, and various other things. Mostly depending on which layer is selected and what content it has at the time.

Works well, but makes the script too difficult to explain how to use it to others. One of those cases where I wrote a script solely for my liking. I'd probably have to make it a tool or multiple button scripts for others to use.
Post Reply