diff --git a/switchy/main.cpp b/switchy/main.cpp index 47d9f8f..f43014e 100644 --- a/switchy/main.cpp +++ b/switchy/main.cpp @@ -1,15 +1,16 @@ #include - -using namespace std; +#include HHOOK hHook = 0; +bool isWindows10 = GetRealOSVersion().dwMajorVersion >= 10; +bool wasPressed = false; LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam; if (p->vkCode == VK_CAPITAL) { - if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) { + if (wParam == WM_KEYDOWN) { if (GetKeyState(VK_CAPITAL)) { UnhookWindowsHookEx(hHook); keybd_event(VK_CAPITAL, 0x3a, 0, 0); @@ -17,10 +18,24 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0); } - HWND hWnd = GetForegroundWindow(); - if (hWnd) { - hWnd = GetAncestor(hWnd, GA_ROOTOWNER); - PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)HKL_NEXT); + if (isWindows10 && !wasPressed) { + wasPressed = true; + keybd_event(VK_LWIN, 0x3a, 0, 0); + keybd_event(VK_SPACE, 0x3a, 0, 0); + } + } + + if (wParam == WM_KEYUP) { + if (isWindows10) { + keybd_event(VK_LWIN, 0x3a, KEYEVENTF_KEYUP, 0); + keybd_event(VK_SPACE, 0x3a, KEYEVENTF_KEYUP, 0); + wasPressed = false; + } else { + HWND hWnd = GetForegroundWindow(); + if (hWnd) { + hWnd = GetAncestor(hWnd, GA_ROOTOWNER); + PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)HKL_NEXT); + } } } diff --git a/switchy/switchy.vcxproj b/switchy/switchy.vcxproj index 340a1a1..4886cc6 100644 --- a/switchy/switchy.vcxproj +++ b/switchy/switchy.vcxproj @@ -76,6 +76,7 @@ Disabled true true + ./ Console @@ -87,6 +88,7 @@ Disabled true true + ./;%(AdditionalIncludeDirectories) Console @@ -100,6 +102,7 @@ true true true + ./ Windows @@ -116,6 +119,7 @@ true true true + ./ Windows @@ -127,6 +131,9 @@ + + + diff --git a/switchy/switchy.vcxproj.filters b/switchy/switchy.vcxproj.filters index 173ccba..1712dc6 100644 --- a/switchy/switchy.vcxproj.filters +++ b/switchy/switchy.vcxproj.filters @@ -1,10 +1,6 @@  - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx @@ -13,10 +9,19 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + Source Files + + + Header Files + + \ No newline at end of file diff --git a/switchy/version.h b/switchy/version.h new file mode 100644 index 0000000..84ae0d2 --- /dev/null +++ b/switchy/version.h @@ -0,0 +1,22 @@ +typedef LONG NTSTATUS, * PNTSTATUS; +#define STATUS_SUCCESS (0x00000000) + +typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + +RTL_OSVERSIONINFOW GetRealOSVersion() { + HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); + + if (hMod) { + RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion"); + if (fxPtr != nullptr) { + RTL_OSVERSIONINFOW rovi = { 0 }; + rovi.dwOSVersionInfoSize = sizeof(rovi); + if (STATUS_SUCCESS == fxPtr(&rovi)) { + return rovi; + } + } + } + + RTL_OSVERSIONINFOW rovi = { 0 }; + return rovi; +} \ No newline at end of file