Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 5eca8fe

Browse files
committed
Added support for Windows 10 language pop-up
1 parent 980199a commit 5eca8fe

4 files changed

Lines changed: 60 additions & 11 deletions

File tree

switchy/main.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
#include <Windows.h>
2-
3-
using namespace std;
2+
#include <version.h>
43

54
HHOOK hHook = 0;
5+
bool isWindows10 = GetRealOSVersion().dwMajorVersion >= 10;
6+
bool wasPressed = false;
67

78
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
89
if (nCode == HC_ACTION) {
910
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
1011

1112
if (p->vkCode == VK_CAPITAL) {
12-
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
13+
if (wParam == WM_KEYDOWN) {
1314
if (GetKeyState(VK_CAPITAL)) {
1415
UnhookWindowsHookEx(hHook);
1516
keybd_event(VK_CAPITAL, 0x3a, 0, 0);
1617
keybd_event(VK_CAPITAL, 0x3a, KEYEVENTF_KEYUP, 0);
1718
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0);
1819
}
1920

20-
HWND hWnd = GetForegroundWindow();
21-
if (hWnd) {
22-
hWnd = GetAncestor(hWnd, GA_ROOTOWNER);
23-
PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)HKL_NEXT);
21+
if (isWindows10 && !wasPressed) {
22+
wasPressed = true;
23+
keybd_event(VK_LWIN, 0x3a, 0, 0);
24+
keybd_event(VK_SPACE, 0x3a, 0, 0);
25+
}
26+
}
27+
28+
if (wParam == WM_KEYUP) {
29+
if (isWindows10) {
30+
keybd_event(VK_LWIN, 0x3a, KEYEVENTF_KEYUP, 0);
31+
keybd_event(VK_SPACE, 0x3a, KEYEVENTF_KEYUP, 0);
32+
wasPressed = false;
33+
} else {
34+
HWND hWnd = GetForegroundWindow();
35+
if (hWnd) {
36+
hWnd = GetAncestor(hWnd, GA_ROOTOWNER);
37+
PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)HKL_NEXT);
38+
}
2439
}
2540
}
2641

switchy/switchy.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Optimization>Disabled</Optimization>
7777
<SDLCheck>true</SDLCheck>
7878
<ConformanceMode>true</ConformanceMode>
79+
<AdditionalIncludeDirectories>./</AdditionalIncludeDirectories>
7980
</ClCompile>
8081
<Link>
8182
<SubSystem>Console</SubSystem>
@@ -87,6 +88,7 @@
8788
<Optimization>Disabled</Optimization>
8889
<SDLCheck>true</SDLCheck>
8990
<ConformanceMode>true</ConformanceMode>
91+
<AdditionalIncludeDirectories>./;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9092
</ClCompile>
9193
<Link>
9294
<SubSystem>Console</SubSystem>
@@ -100,6 +102,7 @@
100102
<IntrinsicFunctions>true</IntrinsicFunctions>
101103
<SDLCheck>true</SDLCheck>
102104
<ConformanceMode>true</ConformanceMode>
105+
<AdditionalIncludeDirectories>./</AdditionalIncludeDirectories>
103106
</ClCompile>
104107
<Link>
105108
<SubSystem>Windows</SubSystem>
@@ -116,6 +119,7 @@
116119
<IntrinsicFunctions>true</IntrinsicFunctions>
117120
<SDLCheck>true</SDLCheck>
118121
<ConformanceMode>true</ConformanceMode>
122+
<AdditionalIncludeDirectories>./</AdditionalIncludeDirectories>
119123
</ClCompile>
120124
<Link>
121125
<SubSystem>Windows</SubSystem>
@@ -127,6 +131,9 @@
127131
<ItemGroup>
128132
<ClCompile Include="main.cpp" />
129133
</ItemGroup>
134+
<ItemGroup>
135+
<ClInclude Include="version.h" />
136+
</ItemGroup>
130137
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
131138
<ImportGroup Label="ExtensionTargets">
132139
</ImportGroup>

switchy/switchy.vcxproj.filters

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<Filter Include="Header Files">
5-
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
6-
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
7-
</Filter>
84
<Filter Include="Source Files">
95
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
106
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
@@ -13,10 +9,19 @@
139
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
1410
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
1511
</Filter>
12+
<Filter Include="Header Files">
13+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
14+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
15+
</Filter>
1616
</ItemGroup>
1717
<ItemGroup>
1818
<ClCompile Include="main.cpp">
1919
<Filter>Source Files</Filter>
2020
</ClCompile>
2121
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="version.h">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
</ItemGroup>
2227
</Project>

switchy/version.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
typedef LONG NTSTATUS, * PNTSTATUS;
2+
#define STATUS_SUCCESS (0x00000000)
3+
4+
typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
5+
6+
RTL_OSVERSIONINFOW GetRealOSVersion() {
7+
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
8+
9+
if (hMod) {
10+
RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
11+
if (fxPtr != nullptr) {
12+
RTL_OSVERSIONINFOW rovi = { 0 };
13+
rovi.dwOSVersionInfoSize = sizeof(rovi);
14+
if (STATUS_SUCCESS == fxPtr(&rovi)) {
15+
return rovi;
16+
}
17+
}
18+
}
19+
20+
RTL_OSVERSIONINFOW rovi = { 0 };
21+
return rovi;
22+
}

0 commit comments

Comments
 (0)