Skip to content

Commit

Permalink
RegisterHotKey will be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jan 28, 2021
1 parent 1c2f8e5 commit 71f6b58
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
{
switch (message)
{
case WM_HOTKEY:
{
auto a = 0;
a++;
a;
// ShowWindow(_window.get(), SW_RESTORE);
// SetFocus(_window.get());
HWND myHwnd = _window.get();
SendMessage(_window.get(), WM_SYSCOMMAND, SC_HOTKEY, (LPARAM)myHwnd);
// break;
return 0;
}
case WM_GETMINMAXINFO:
{
_OnGetMinMaxInfo(wparam, lparam);
Expand Down Expand Up @@ -849,14 +861,29 @@ void IslandWindow::SetGlobalHotkey(const winrt::Microsoft::Terminal::TerminalCon
if (hotkey)
{
auto modifiers = hotkey.Modifiers();
WPARAM wParam = hotkey.Vkey() |
(WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? HOTKEYF_ALT << 8 : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? HOTKEYF_CONTROL << 8 : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? HOTKEYF_SHIFT << 8 : 0);
auto result = SendMessage(_window.get(), WM_SETHOTKEY, wParam, 0);
result;
auto a = result + 1;
a;
// WPARAM wParam = hotkey.Vkey() |
// (WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? HOTKEYF_ALT << 8 : 0) |
// (WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? HOTKEYF_CONTROL << 8 : 0) |
// (WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? HOTKEYF_SHIFT << 8 : 0);
// auto result = SendMessage(_window.get(), WM_SETHOTKEY, wParam, 0);
// result;
// auto a = result + 1;
// a;

auto MODs = MOD_NOREPEAT |
(WI_IsFlagSet(modifiers, KeyModifiers::Alt) ? MOD_ALT : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Ctrl) ? MOD_CONTROL : 0) |
(WI_IsFlagSet(modifiers, KeyModifiers::Shift) ? MOD_SHIFT : 0);
auto res = RegisterHotKey(_window.get(), 1, MODs, hotkey.Vkey());
LOG_LAST_ERROR_IF(!res);
// if (!res)
// {
// // auto gle = GetLastError();

// }
// res;
// auto b = !res;
// b;
}
}

Expand Down

0 comments on commit 71f6b58

Please sign in to comment.