Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only some keys sent to keyboard handler on Windows #59

Open
ostinato opened this issue Apr 6, 2018 · 3 comments
Open

Only some keys sent to keyboard handler on Windows #59

ostinato opened this issue Apr 6, 2018 · 3 comments

Comments

@ostinato
Copy link

ostinato commented Apr 6, 2018

CFrame onKeyDown/Up etc only get a small subset of keys, ie the ones listed in vstkeycode.h struct VstVirtualKey, ie shift, ctrl, space, F1-F12, arrows etc.
But no letters or digits.

In fact it looks like the VstKeyCode .character member is always 0 on windows.

If I read Mac code in /platform/mac/ cocoahelpers.mm right, this is not the case on Mac;
there the .character member is populated with ASCII value.

I can ofc hack the win32frame.cpp translateWinVirtualKey function, or use KeyboardHook,
but just wanted to note this seems an omission.

Or is there some logic to this behaviour?

Thanks,
/re

@scheffle
Copy link
Collaborator

scheffle commented Apr 8, 2018

Hi,
normally on Windows, the host will send the key event to the plug-in. That's why there's no such support in VSTGUI itself yet. This is different on macOS where the host does not send the key event to the plugin. (Note that the character value is not populated with ASCII, it's populated with the unicode character).
Feel free to make a pull request for Windows if you like.

@ostinato
Copy link
Author

ostinato commented Apr 8, 2018

Thanks for reply.

I noted that at least the JUCE host sends WM_CHAR to the plugin, so I could hack win32frame.cpp copying code from WM_KEYDOWN to WM_CHAR:

	case WM_CHAR:
	{
		VstKeyCode key{};
		if (GetAsyncKeyState(VK_SHIFT) < 0)
			key.modifier |= MODIFIER_SHIFT;
		if (GetAsyncKeyState(VK_CONTROL) < 0)
			key.modifier |= MODIFIER_CONTROL;
		if (GetAsyncKeyState(VK_MENU) < 0)
			key.modifier |= MODIFIER_ALTERNATE;
		key.character = static_cast<int32_t>(wParam);
		if (pFrame->platformOnKeyDown(key))
			return 0;

		if (IsWindow(oldFocusWindow))
		{
			WNDPROC oldProc = (WNDPROC)GetWindowLongPtr(oldFocusWindow, GWLP_WNDPROC);
			if (oldProc && oldProc != WindowProc)
				return CallWindowProc(oldProc, oldFocusWindow, message, wParam, lParam);
		}
		break;
	}
	case WM_KEYDOWN:
	// ...

Not sure if that's the correct way to do it, one needs to use utf8 codecvt facet to create VSTGUI strings.
(doesn't bother me as I just wanted digits)

Just using a copy of the code, but I can look at pull requesting.
I have a few changes and additions in my project...

@scheffle
Copy link
Collaborator

scheffle commented Apr 9, 2018

The wide string to utf8 string conversion can be done via the UTF8StringHelper class from winsupport.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants