Getting keypresses???

ymerejsasnak
Posts: 52
Joined: Thu Jun 04, 2020 2:08 am

Getting keypresses???

Post by ymerejsasnak » Fri Mar 26, 2021 10:04 pm

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

flucatcher
Posts: 68
Joined: Mon Jan 28, 2019 5:51 am

Re: Getting keypresses???

Post by flucatcher » Sat Mar 27, 2021 11:21 am

Couple of stupid ideas:
Your module isnt selected (click on it)
You havent published your changes

ColinP
Posts: 87
Joined: Mon Aug 03, 2020 7:46 pm

Re: Getting keypresses???

Post by ColinP » Sat Mar 27, 2021 2:43 pm

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.

ymerejsasnak
Posts: 52
Joined: Thu Jun 04, 2020 2:08 am

Re: Getting keypresses???

Post by ymerejsasnak » Sat Mar 27, 2021 4:50 pm

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

ColinP
Posts: 87
Joined: Mon Aug 03, 2020 7:46 pm

Re: Getting keypresses???

Post by ColinP » Sun Mar 28, 2021 1:12 pm

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;

ColinP
Posts: 87
Joined: Mon Aug 03, 2020 7:46 pm

Re: Getting keypresses???

Post by ColinP » Sun Mar 28, 2021 1:23 pm

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.

ymerejsasnak
Posts: 52
Joined: Thu Jun 04, 2020 2:08 am

Re: Getting keypresses???

Post by ymerejsasnak » Sun Mar 28, 2021 3:07 pm

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;

ymerejsasnak
Posts: 52
Joined: Thu Jun 04, 2020 2:08 am

Re: Getting keypresses???

Post by ymerejsasnak » Wed Mar 31, 2021 5:24 pm

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

ColinP
Posts: 87
Joined: Mon Aug 03, 2020 7:46 pm

Re: Getting keypresses???

Post by ColinP » Thu Apr 01, 2021 3:58 pm

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.

ymerejsasnak
Posts: 52
Joined: Thu Jun 04, 2020 2:08 am

Re: Getting keypresses???

Post by ymerejsasnak » Fri Apr 02, 2021 4:26 pm

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

Post Reply