Last active
September 7, 2017 17:49
-
-
Save SEVEZ/72bed0f009bedf4e66a26c34797d0eb9 to your computer and use it in GitHub Desktop.
PS_keyOps - use long or double hotkeys press for different commands execution #Final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from threading import Thread | |
import maya.utils as u | |
import maya.cmds | |
global glTimer | |
try: glTimer | |
except NameError: glTimer = -1 | |
def myfunc2( r ): | |
maya.cmds.sphere( radius=r ) | |
print( "single press" ) | |
def myfunc3( r ): | |
maya.cmds.cylinder( radius=r ) | |
print( "double press" ) | |
def myfunc( time_tol ): | |
global glTimer | |
current = time.time() | |
if glTimer > 0 : | |
delta = current - glTimer | |
glTimer = current | |
if ( delta < time_tol ): | |
glTimer = -1 | |
u.executeDeferred( "myfunc3( '%d' )" % 1 ) | |
else: | |
glTimer = current | |
time.sleep( time_tol ) | |
if glTimer > 0: | |
glTimer = -1 | |
u.executeDeferred( "myfunc2( '%d' )" % 1 ) | |
t = Thread( target=myfunc, args=( 0.2, ) ) | |
t.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
PS_keyOps - use long or double hotkeys press for different commands execution | |
Pavel Sevets 2016 | |
[email protected] | |
USAGE: | |
1) Long key press | |
Assign command to Press | |
import PS_keyOps as psko; psko.PS_keyLong_Press( func1, func2 ) | |
Assign command to Release | |
import PS_keyOps as psko; psko.PS_keyLong_Release | |
2) Double key press | |
Assign command to Press | |
import PS_keyOps as psko; psko.PS_keyDouble_Press( func1, func2 ) | |
EXAMPLE: | |
1) Press once for regular save or twice - for incremental save | |
import PS_keyOps as psko | |
reload( psko ) | |
import maya.mel | |
op1 = 'maya.mel.eval( \'checkForUnknownNodes(); SaveScene\' )' | |
op2 = 'maya.mel.eval( \'checkForUnknownNodes(); incrementAndSaveScene 0\' )' | |
psko.PS_keyDouble_Press( op1, op2 ) | |
2) Press short to create a sphere or long - for cylinder | |
import PS_keyOps as psko | |
reload( psko ) | |
import maya.cmds | |
op1 = 'maya.cmds.sphere( r=1 )' | |
op2 = 'maya.cmds.cylinder( r=1 )' | |
psko.PS_keyLong_Press( op1, op2 ) | |
P.S. Use 'pass' as op for empty execution | |
''' | |
# LONG KEY PRESS | |
import maya.utils as mu | |
from threading import Thread | |
import time | |
global gKeyLong | |
global gKeyDouble | |
def PS_keyLong_Exec( op1, op2 ): | |
time.sleep( 0.2 ) | |
global gKeyLong | |
if gKeyLong: | |
mu.executeDeferred( op2 ) | |
else: | |
mu.executeDeferred( op1 ) | |
def PS_keyLong_Press( op1, op2 ): | |
global gKeyLong | |
gKeyLong = 1 | |
t = Thread( target = PS_keyLong_Exec, args = ( op1, op2, ) ) | |
t.start() | |
def PS_keyLong_Release(): | |
global gKeyLong | |
gKeyLong = 0 | |
# DOUBLE KEY PRESS | |
def PS_keyDouble_Exec( op1, op2 ): | |
global gKeyDouble | |
current = time.time() | |
if gKeyDouble > 0 : | |
delta = current - gKeyDouble | |
gKeyDouble = current | |
if ( delta < 0.2 ): | |
gKeyDouble = -1 | |
mu.executeDeferred( op2 ) | |
else: | |
gKeyDouble = current | |
time.sleep( 0.2 ) | |
if gKeyDouble > 0: | |
gKeyDouble = -1 | |
mu.executeDeferred( op1 ) | |
def PS_keyDouble_Press( op1, op2 ): | |
global gKeyDouble | |
try: gKeyDouble | |
except NameError: gKeyDouble = -1 | |
t = Thread( target = PS_keyDouble_Exec, args = ( op1, op2, ) ) | |
t.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment