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

[Problem/Bug]: Why is the hotkey CTRL + J slipping through? #4636

Closed
ajtruckle opened this issue Jun 18, 2024 · 1 comment
Closed

[Problem/Bug]: Why is the hotkey CTRL + J slipping through? #4636

ajtruckle opened this issue Jun 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ajtruckle
Copy link

What happened?

According to my code the hotkey CTRL + J should be supressed.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

125.0.2535.92

SDK Version

2535.41

Framework

Win32

Operating System

Windows 11

OS Version

10.0.22631

Repro steps

void CWebBrowser::AddAcceleratorKeyPressedHandler()
{
	if (m_pImpl->m_webController != nullptr)
	{
		CHECK_FAILURE(m_pImpl->m_webController->add_AcceleratorKeyPressed(
			Callback<ICoreWebView2AcceleratorKeyPressedEventHandler>(
				[this](
					ICoreWebView2Controller* sender,
					ICoreWebView2AcceleratorKeyPressedEventArgs* args) -> HRESULT {
						COREWEBVIEW2_KEY_EVENT_KIND kind;
						CHECK_FAILURE(args->get_KeyEventKind(&kind));
						// We only care about key down events.
						if (kind == COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN ||
							kind == COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN)
						{
							UINT key;
							CHECK_FAILURE(args->get_VirtualKey(&key));
							// Check if the key is one we want to handle.
							bool bDetected = false;
							std::function<void()> action = GetAcceleratorKeyFunction(key, bDetected);
							if (action)
							{
								// Keep the browser from handling this key, whether it's autorepeated or
								// not.
								CHECK_FAILURE(args->put_Handled(TRUE));

								// Filter out autorepeated keys.
								COREWEBVIEW2_PHYSICAL_KEY_STATUS status;
								CHECK_FAILURE(args->get_PhysicalKeyStatus(&status));
								if (!status.WasKeyDown)
								{
									// Perform the action asynchronously to avoid blocking the
									// browser process's event queue.
									RunAsync(action);
								}
							}

							if (bDetected && action == nullptr)
							{
								// Keep the browser from handling this key, whether it's autorepeated or
								// not.
								CHECK_FAILURE(args->put_Handled(TRUE));
							}
						}
						return S_OK;
				})
			.Get(),
		&m_acceleratorKeyPressedToken));
	}
}

std::function<void()> CWebBrowser::GetAcceleratorKeyFunction(UINT key, bool &rbDetected)
{
	// No function keys
	if (!IsCTRLpressed() && !IsSHIFTpressed() && !IsALTpressed())
	{
		switch (key)
		{
		case VK_F1:
			rbDetected = true;
			return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_HELP_HELP, NULL); };
		case VK_F5:
			rbDetected = true;
			return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_VIEW_REFRESH, NULL); };
		case VK_F6:
			rbDetected = true;
			if (GetEditorType() == EditorType::MeetingEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_FILE_DOWNLOAD_SCHEDULE_INFORMATION, NULL); };
			break;
		case VK_F7:
			rbDetected = true;
			if (GetEditorType() == EditorType::MeetingEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_MWB_DATA_EXPORT, NULL); };
			break;
		default:
			return nullptr;
		}
	}
	// CTRL + SHIFT function keys
	else if (IsCTRLpressed() && IsSHIFTpressed() && !IsALTpressed())
	{
		switch (key)
		{
		case _TINT(L'D'):
			rbDetected = true;
			if (GetEditorType() == EditorType::MeetingEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_EDIT_DUTY_ASSIGNMENTS, NULL); };
			break;
		case _TINT(L'I'):
			rbDetected = true;
			if (GetEditorType() == EditorType::MeetingEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_MWT_TRANSFER_FROM_PC, NULL); };
			break;
		case _TINT(L'O'):
			rbDetected = true;
			if (GetEditorType() == EditorType::AssignmentEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_OPTIONS_COLUMNS, NULL); };
			break;
		case _TINT(L'T'):
			rbDetected = true;
			if (GetEditorType() == EditorType::MeetingEditor)
				return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_EDIT_MEETING_TIMES, NULL); };
			break;
		default:
			return nullptr;
		}
	}
	// CTRL function key
	else if (IsCTRLpressed() && !IsSHIFTpressed() && !IsALTpressed())
	{
		switch (key)
		{
		case _TINT(L'P'):
			rbDetected = true;
			return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_FILE_PRINT_PREVIEW, NULL); };
		case _TINT(L'S'):
			rbDetected = true;
			return [this] { GetParentWindow()->SendMessage(WM_COMMAND, ID_FILE_SAVE, NULL); };
		default:
			return nullptr;
		}
	}

	return nullptr;
}

According to my code logic, CTRL + J should end up in the final else clause and as a result return the default, which is nullptr. So the parent code should suppress that action. Yet, I see a Download window come up on the display.

Side: point:
In your template for submitting as bug you have a typo:

Does this issue reporduce in the Edge or Chrome browsers?

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

@ajtruckle ajtruckle added the bug Something isn't working label Jun 18, 2024
@ajtruckle
Copy link
Author

Please close this issue. I realise that I need to add a specific switch node so that rbDetected is set as true.

@victorhuangwq victorhuangwq closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants