Page 1 of 2

Getting keypresses???

Posted: Fri Mar 26, 2021 10:04 pm
by ymerejsasnak
Hello all....

I'm having an issue using keypresses. I have code that runs under the appropriate Notify case -- and it works fine when running the module from the Designer. But when I export/publish the module and try using the module in VM (both standalone and as VST) none of the keypresses activate the expected functionality.

Basically, my brain is too tired to debug/troubleshoot this right now, so I'm just seeing if anyone else has any useful input. Maybe it's a VM bug? Maybe it's my module's bug? Maybe I'm misunderstanding something about how key presses work?? I dunno.

If anyone has anything helpful, thanks in advance. If not, no worries. :)

JK

Re: Getting keypresses???

Posted: Sat Mar 27, 2021 11:21 am
by flucatcher
Couple of stupid ideas:
Your module isnt selected (click on it)
You havent published your changes

Re: Getting keypresses???

Posted: Sat Mar 27, 2021 2:43 pm
by ColinP
I came across this problem too. And yes the module did have focus.

It's a while back and I can't remember the exact details but the problem was only with certain "special" keys such as the cursor keys. It was annoying as everything worked in VMD but when I published low and behold the code didn't work in VM

I concluded that (as with several other differences between VMD and VM) VM trapped certain key press events and didn't pass them on.

If anyone can give a definitive answer on this it would be great as cursor key input would make one or two of the modules I have in development a bit easier to use.

Re: Getting keypresses???

Posted: Sat Mar 27, 2021 4:50 pm
by ymerejsasnak
Thanks for the replies.

Yes the module has focus and I published again just to make sure I hadn't had an absent minded moment...still nothing.

And I'm using a large majority of the letter keys - none of which work outside of the Designer. It would seem weird for VM to trap such a huge number of keys but yet offer the keypress notification and object, so I'd like to think that's not it...but maybe.

I should have a chance to mess with things later. If I get anywhere I'll post my results.

JK

Re: Getting keypresses???

Posted: Sun Mar 28, 2021 1:12 pm
by ColinP
Hi JK,

You should definitely be able to get basic character input. The following should work in Notify()...

Code: Select all

	case Key_Press:     // sent when module has keyboard focus and a key is pressed; object is a VoltageKeyPressInfo object
	{
		VoltageKeyPressInfo keyInfo = (VoltageKeyPressInfo) object;
		if( keyInfo.IsNonCharacterKeyCode() )
		{
			// handle special keys...
		}
		else
		{
			// handle regular characters...
			char c = (char) keyInfo.GetCharacter();
			
			// c should contain regular character
		}
	}
	break;

Re: Getting keypresses???

Posted: Sun Mar 28, 2021 1:23 pm
by ColinP
The problem I have is with the following code...

Code: Select all

	case Key_Press:     // sent when module has keyboard focus and a key is pressed; object is a VoltageKeyPressInfo object
	{
		VoltageKeyPressInfo keyInfo = (VoltageKeyPressInfo) object;
		if( keyInfo.IsNonCharacterKeyCode() )
		{
			if( keyInfo.IsUpArrowKey() )
				raisePitch();
			else if( keyInfo.IsDownArrowKey() )
				lowerPitch();
		}
	}
	break;
This works as expected in VMD but in VM the up and down arrow key presses get trapped by VM and cause it to scroll. The scroll implementation is awful too but that is another issue, one I have addressed elsewhere on this forum.

Re: Getting keypresses???

Posted: Sun Mar 28, 2021 3:07 pm
by ymerejsasnak
Hi Colin,

Thanks for the posts. Sadly, I have what appears to be bad news. I started a new project just to see what would happen. All I added was a text label and the code below in the Key_Press case. It works exactly as expected in VMD, but after publishing it again seems to not be detecting ANY keypresses. I'm off to CA support with this one, I guess. :|

Code: Select all

case Key_Press:
{
	VoltageKeyPressInfo key = (VoltageKeyPressInfo) object;
				
	if (key.IsNonCharacterKeyCode()) {
		textLabel1.SetText("Non-char");
	}
	else {
		textLabel1.SetText("" + (char)key.GetCharacter());
	}
}
break;

Re: Getting keypresses???

Posted: Wed Mar 31, 2021 5:24 pm
by ymerejsasnak
Quick update.

Heard back from Greg. This is in fact a bug that they'll fix in the future.

But he also said that for now, adding an Editable Label (invisible/offscreen/whatever is fine) will let the module get the keypresses.

I tried it and it works! Fix is good enough for me for now. :)

JK

Re: Getting keypresses???

Posted: Thu Apr 01, 2021 3:58 pm
by ColinP
Thanks for the update Jeremy.

I tried the kludge but VM still traps the cursor keys interpreting them as scroll commands. Also the delete key is trapped and interpreted as a delete module command which is a little drastic!

So it looks like the VoltageKeyPressInfo methods IsUpArrowKey, IsDownArrowKey, IsLeftArrowKey, IsRightArrowKey and IsDeleteKey are effectively useless at the moment. Unless I've made a mistake somewhere.

It makes sense for VM to trap them most of the time but one ought to be able to register interest in such events.

I did come across one widget library that allowed such registration. It might have been when I was working on SunOS/UNIX stuff, if so X-11 Windows. Anyway if Dan or whoever is interested the solution to this problem is a "wants event" method.

Re: Getting keypresses???

Posted: Fri Apr 02, 2021 4:26 pm
by ymerejsasnak
Yeah, I figured out the delete key wouldn't work the hard way. :)

Anyway, I was just working on some stuff a bit and noticed that if you have a modifier key down (shift, etc) the cursor keys don't seem to be captured to control the scrollbar and will actually work as intended in the module. Not sure if this helps your situation, but figured I'd mention it.

JK