ZBrushCentral

Question : Sleep command interfering with button info window

Hi,

I am trying to enable multi function buttons as we did in ZBrush 2, in other words left clicking the button has one function and SHIFT + left clicking the same button has another function. In Zbrush 2 this worked fine using the [Sleep,…] command to detect modifier key press and release. It also seems to work fine in ZBrush 3 until you, for example, hold CTRL and hover over a button. The button description window is then moved to the top of the screen and flickers while the modifier key is pressed. It still works but the sideeffect is unacceptable.

This is the code I have used in ZBrush 2 that is causing trouble in ZBrush 3:

 [VarDef, KeyPressID, 0] 
 
[IButton, "Testing the sleep command", ,
 
[If, ((KeyPressID) & 256) = 256,
[Note, "Shift key held"]
[VarSet, KeyPressID, 0]
]
 
]
 
[Sleep,0.001,
 
[If, SleepResult == 64, // modifier pressed
[VarSet, KeyPressID, [IGet, Preferences:utilities:viewkeyboardstatus] ]
]
 
[If, SleepResult == 128, // modifier released
[VarSet, KeyPressID, 0]
]
 
[SleepAgain]
, 64 | 128 ,SleepResult
]

Not sure how to tackle this problem apart from creating buttons with separate functions which I really want to avoid in this script. I have tried various combinations of [SleepAgain,…] wake up values, alternating wake up values (depending on sleepresult) and also breaking down in tears. The latter helped clear my bunged up nose but apart from that, no luck.

Any ideas?

Hi TV,
The flickering is nasty, I agree. Off hand I can’t think of anyway around it. Myself, I’ve been more prone to nose bleeds lately when working with scripts in 3.1. and I still have pending plugins I’m reluctant to release until the many loose ends in ZScripting are fixed in the next ZB update.

Sven

The solution I found was to make sure that the script didn’t remain active at the end of the button code. Obviously a way around the possibility of calling the welcome screen needs to be found but this code works for me:


[VarDef, KeyPressID,[IGet, Preferences:utilities:viewkeyboardstatus] ] 


[IButton, "SleepTest","Testing the sleep command" ,
[Sleep,0.001, 
[If, SleepResult == 64, // modifier pressed
[VarSet, KeyPressID, [IGet, Preferences:utilities:viewkeyboardstatus] ]
] 
[If, SleepResult == 128, // modifier released
[VarSet, KeyPressID, 0]
]
, 64 | 128 ,SleepResult
]
[If, ((KeyPressID) & 256)= 256,
[Note, "Shift key held"]
[VarSet, KeyPressID, 0]
[IPress,zscript:previous]
,
[Note, "Button pressed"]
[VarSet, KeyPressID, 0]
[IPress,zscript:previous]
]
]

What happens if, using Marcus’ script, you substitute an [Exit] command for each of the [IPress, ZScript:Previous] commands?

Sven

Marcus, thank you. Unfortunately it seems the sleep command needs to run continuously to properly register presses and releases. Your code right now, with and without [Ipress, ZScript:Previous] or [Exit] will show a “shift key held” when it is not. Try tapping the shift key or even use a shortcut involving it (Ctrl + Shift + L) before pressing the SleepTest button.

I tried issuing an [IKeyPress, ] command to perhaps clear the keyboard status but it still registers the Shift key.

John,

and I still have pending plugins I’m reluctant to release until the many loose ends in ZScripting are fixed in the next ZB update.

Brilliant!! Sorry, I meant “Yes. That is also why I have not released my scripts”. Finally I have a good reason for postponing my scripts even further. Bad jokes aside, I know what you mean. As much as I love the new features and power of ZBrush 3 the deeper you dig it becomes apparent that the zscripting part is somewhat neglected. Of course in my opinion.

I still have hopes this issue can be resolved without a version upgrade to ZBrush. Marcus I am looking at you :smiley: After all, you came up with the modifier key detection in the first place.

I swear this worked when I tested it first… and now it doesn’t. It doesn’t matter where the Sleep command is, with previous in there the thing doesn’t register correctly. :frowning:

OK, I’ve looked at this some more. This does work for me and I’d be interested to know if it works for anyone else!

What I did was to create a separate plugin with a button that contains no code. This is called ‘Blank’ in my code below. The idea behind it is to give a reliable means of exiting a zscript/plugin without calling any undesirable behaviour. By calling it at the end of the sleep button the Sleep command is ended and any side effects avoided.

Here’s my code:


[If,1,[IKeyPress,13]]
[VarDef, KeyPressID,[IGet, Preferences:utilities:viewkeyboardstatus]] 


[IButton, "ZPlugin:Marcus Tools:Sleep","Testing the sleep command" ,
[If, ((KeyPressID) & 256)== 256,
[Note, "Shift key held"]
[VarSet, KeyPressID, 0]
,
[Note, "Button pressed"]
]
[IPress,ZPlugin:Marcus Tools:Blank]
]


[Sleep,0.001, 
[If, SleepResult == 64, // modifier pressed
[VarSet, KeyPressID, [IGet, Preferences:utilities:viewkeyboardstatus] ]
] 
[If, SleepResult == 128, // modifier released
[VarSet, KeyPressID, 0]
]
[SleepAgain]
, 64 | 128 ,SleepResult
]


That works for me, although exiting the zplugin like that brought its own problem.

Activating a separate zplugin after each button press revealed a problem with scripted UI buttons that are disabled through their button definition. A slight flicker of those buttons occurred quite often when the plugin was activated. Using a memblock to test if it is the first time the plugin is loaded and disabling the buttons solved that.

Thank you for your time Marcus and Svengali.