如何从Maya 2016 python中的keyboad中获取输入

时间:2015-07-27 14:39:53

标签: python scripting keyboard maya autodesk

我想知道Maya 2016中是否有选项,python脚本,以从键盘获取数据,但不是打开UI窗口或类似的东西 '的raw_input'在python中执行命令,但是直播,就像你玩游戏一样,按下按钮,就会发生一个动作。 有没有办法在Maya python脚本中执行此操作?

1 个答案:

答案 0 :(得分:1)

def moveCurrent(direction):
    getSel = cmds.ls(sl=True)
    if getSel:
        if direction == "up":
            currentVal = cmds.getAttr("%s.tx" % getSel[0])
            cmds.setAttr("%s.tx" % getSel[0], currentVal + 10)
        elif direction == "down":
            currentVal = cmds.getAttr("%s.tx" % getSel[0])
            cmds.setAttr("%s.tx" % getSel[0], currentVal - 10)
        elif direction == "left":
            currentVal = cmds.getAttr("%s.tz" % getSel[0])
            cmds.setAttr("%s.tz" % getSel[0], currentVal - 10)
        elif direction == "right":
            currentVal = cmds.getAttr("%s.tz" % getSel[0])
            cmds.setAttr("%s.tz" % getSel[0], currentVal + 10)

cmds.nameCommand( 'moveCurrentSelectionFuncUp', ann='Move Selected Mode', c='python("moveCurrent(\\\"up\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncDown', ann='Move Selected Mode b', c='python("moveCurrent(\\\"down\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncLeft', ann='Move Selected Mode c ', c='python("moveCurrent(\\\"left\\\")")' )
cmds.nameCommand( 'moveCurrentSelectionFuncRight', ann='Move Selected Mode d ', c='python("moveCurrent(\\\"right\\\")")' )
cmds.hotkey( keyShortcut='F5', name='moveCurrentSelectionFuncUp' )      
cmds.hotkey( keyShortcut='F6', name='moveCurrentSelectionFuncDown' ) 
cmds.hotkey( keyShortcut='F7', name='moveCurrentSelectionFuncLeft' ) 
cmds.hotkey( keyShortcut='F8', name='moveCurrentSelectionFuncRight' )

确保在上面的代码段运行后有视口焦点。