Key Up Event

Hi Friends,

i would like to create a hotbar like in Maya: If you hold Space pressed it appears and disappears immediately if you release the key. To start the script by pressing a key is easy: just assign a hotkey to it.

BUT how i can check during the script is running, about the state of a key? I need an event handler like "on key up ...".

thanks!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Marco Brunetta's picture

Well it would probably be

Well it would probably be easier to instead of having to keep the key pressed, to have it appear the first time it's pressed and have it disappear the second. If you really need it to work only when it's pressed, then you can probably do something with dotNET. Maybe the System.Windows.Input class would help.

Anubis's picture

There no such event handler

There no such event handler like "on key up ...", so you'll need some fake trick. Currently you can track only 4 keyboard keys for their state:

keyboard.shiftPressed
keyboard.controlPressed
keyboard.altPressed
keyboard.escPressed

i.e. for example copy the next snippet to new script and evaluate all by Cltr+E

if keyboard.controlPressed then
	print "It works!"
else print "Huh?!..."

so, just before you losing time in experiments with callbacks, just read what I'll do in this case, and that will be pass the key tracking in timer (rollout controller). So, there is first pass solving:

rollout exampleRollout "Example"
(
	label note "Let's see..."
	timer watcher active:true interval:100 -- ie 10 times per sec.
 
	on watcher tick do
	(
		if not keyboard.controlPressed do
			destroyDialog exampleRollout
	)
)
createDialog exampleRollout

I say 1st pass because there's a discomfort, CTRL key must be pressed and if you run this via installed macroScript and if to say you assign key "H", then holding CTRL will be accepted as Ctrl+H and if this is a valid shortcut, you know, it will run instead. So in 2nd bypass I'll add another timer which to delay a few secs (2 for example) and then activate the main closing timer. This way you can press and hold CTRL key after rollout opened, and as in the 1 pass - it will stay open until you release control key:

rollout exampleRollout "Example"
(
	local sec = 0
	label note "Let's see..."
	timer delay interval:1000 active:true
	timer closer interval:100 active:false
 
	on delay tick do
	(
		if sec >= 2 then
		(
			delay.active = false -- stop this
			closer.active = true -- start this
		)
		else (sec += 1) -- increment counter
	)
	on closer tick do
	(
		if not keyboard.controlPressed do
			destroyDialog exampleRollout
	)
)
createDialog exampleRollout

I hope this help!

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.