{"id":147,"date":"2009-10-22T13:21:08","date_gmt":"2009-10-22T12:21:08","guid":{"rendered":"http:\/\/david.buttress.me.uk\/blog\/?p=147"},"modified":"2009-10-22T13:21:08","modified_gmt":"2009-10-22T12:21:08","slug":"timed-maya-hotkeys","status":"publish","type":"post","link":"http:\/\/david.buttress.me.uk\/blog\/?p=147","title":{"rendered":"timed Maya Hotkeys"},"content":{"rendered":"<p>I like the functionality of the space bar in Maya, hit it quickly and it swaps between single and quad view, but hold it and it shows you the hotbox and release and it leaves the panel views the same. I wanted to replicate this timed nature in some of my own hotkeys. It was actually pretty simple; using the PRESS and RELEASE hotkey settings and a very simple timer check you can change the command depending on the length of time the hotkey was held for.<\/p>\n<p>Below is a sample function using this idea, you would just need to rename some stuff and fill in the parts that actually do something when the key is pressed or held. I&#8217;ve used this idea to create some extra functionality for hiding\/showing, and also a modified fit to panel command that allows different levels of zoom when holding the button.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\nglobal proc timedHotkeyFunction()\r\n{\r\n\tglobal float $timedHotkey_timer;\r\n\r\n\t\/\/Use -1 to reset the timer on release\r\n\tif ( $timedHotkey_timer &lt; 0 )\r\n\t{\r\n\t\t$timedHotkey_timer = `timerX`;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tfloat $heldTime = `timerX -startTime $timedHotkey_timer`;\r\n\t\t$timedHotkey_timer = -1;\r\n\r\n\t\t\/\/Resets the timer if the time is too long, this is to guard against\r\n\t\t\/\/cases where the press and release get mixed round.\r\n\t\tif ( $heldTime &gt; 10 )\r\n\t\t{\r\n\t\t\t$timedHotkey_timer = `timerX`;\r\n\t\t\tprint &quot;\\nReseting Hotkey timer - held for too long!&quot;;\r\n\t\t}\r\n\t\t\/\/Time to define a press or a hold, 0.3 seems to work quite well\r\n\t\telse if ( $heldTime &lt; 0.3 )\r\n\t\t{\r\n\t\t\tprint &quot;\\nPressed!&quot;;\r\n\t\t\t\/\/******************************************************************\r\n\t\t\t\/\/Code for pressed function here.\r\n\t\t\t\/\/******************************************************************\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprint &quot;\\nHeld!&quot;;\r\n\t\t\t\/\/******************************************************************\r\n\t\t\t\/\/Code for hold function here.\r\n\t\t\t\/\/******************************************************************\r\n\t\t}\r\n\r\n\t}\r\n}\r\n\r\n\/\/Define the runTimeCommand that will show up in the hotkey editor, this command\r\n\/\/needs to be assigned to both the PRESS and RELEASE hotkeys\r\nif ( !`runTimeCommand -q -ex timedHotkeyTest` )\r\n{\r\n\trunTimeCommand\r\n\t\t-annotation &quot;Set this to both PRESS and RELEASE on your hotkey&quot;\r\n\t\t-command (&quot;timedHotkeyFunction&quot;)\r\n\t\ttimedHotkeyTest;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I like the functionality of the space bar in Maya, hit it quickly and it swaps between single and quad view, but hold it and it shows you the hotbox and release and it leaves the panel views the same. I wanted to replicate this timed nature in some of my own hotkeys. It was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,4],"tags":[],"_links":{"self":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/147"}],"collection":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":25,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":191,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/191"}],"wp:attachment":[{"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/david.buttress.me.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}