I do not like the default windows start menu and want to change the windows key to open to open Powertoys Run and taskbar instead, whilst this can’t be done in Powertoys settings I can do it with hooks in C++ (or Autohotkey but I have no experience with this unlike C++).
Is there a way to meet all of the following conditions with C++ code, or is there a better of doing it?
Opens Powertoys Run,
Opens Taskbar (and keeps taskbar open the whole time Powertoys Run is open),
Every windows key + ‘something’ shortcut (e.g. windows + v) still works.
I have already made changing windows to alt+space possible with hooks but the taskbar doesn’t stay open, it opens and then closes again (presumably because Run takes focus?). And shortcuts don’t work, it just opens Run instead.
This is the code so far:
#include "main.h"
#include <Windows.h>
#include <iostream>
HHOOK keyboardHook;
void ShowTaskbar()
{
//Find the taskbar window
HWND taskbar = FindWindow(L"Shell_TrayWnd", NULL);
if (taskbar)
{
ShowWindow(taskbar, SW_SHOW);
SetForegroundWindow(taskbar);
}
else
{
std::cout << "Failed to find the Taskbar window.n";
}
}
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* pKeyboard = (KBDLLHOOKSTRUCT*)lParam;
// Check for Windows key press
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
{
if (pKeyboard->vkCode == VK_LWIN)
{
return 1;
}
}
// Check for Windows key release and send Alt+Space
if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
{
if (pKeyboard->vkCode == VK_LWIN)
{
keybd_event(VK_MENU, 0, 0, 0);
keybd_event(VK_SPACE, 0, 0, 0);
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
ShowTaskbar();
return 1;
}
}
}
return CallNextHookEx(keyboardHook, nCode, wParam, lParam);
}
void SetHook()
{
keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 0);
if (!keyboardHook) {
std::cerr << "Failed to install hook." << std::endl;
}
}
void RemoveHook()
{
UnhookWindowsHookEx(keyboardHook);
}
int main()
{
SetHook();
std::cout << "Press ESC to exit..." << std::endl;
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
RemoveHook();
return 0;
};
(Note some of this was made with GPT so if it’s a bit weird that’s why.)
X64 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.