I have tried numerous times with diffrent types of keyboard hooks and still wont work. Here is my code
#include <Windows.h>
HWND window1 = FindWindow(NULL, "Window Title 1");
HWND window2 = FindWindow(NULL, "Window Title 2");
void SwitchWindows(HWND currentWindow, HWND nextWindow) {
ShowWindow(currentWindow, SW_HIDE); // Hide the current window
ShowWindow(nextWindow, SW_SHOW); // Show the next window
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {`your text`
if (nCode >= 0) {
if (wParam == WM_KEYDOWN) {
KBDLLHOOKSTRUCT* kbdStruct = (KBDLLHOOKSTRUCT*)lParam;
// Detect the key press you want to use for switching windows (e.g., F1)
if (kbdStruct->vkCode == VK_F1) {
// Switch from window1 to window2
SwitchWindows(window1, window2);
} else if (kbdStruct->vkCode == VK_F2) {
// Switch from window2 to window1
SwitchWindows(window2, window1);
}
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
// Install the keyboard hook
HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, hModule, 0);
break;
case DLL_PROCESS_DETACH:
// Unhook and clean up
UnhookWindowsHookEx(hook);
break;
}
return TRUE;
}
and yes i have enterd my windows names. Can anyone help
i want it to find two specific windows and switch between them based on what key is pressed.