spiegel-keyman/windows/src/engine/keyman32/syskbdnt.cpp
Marc Durdin b65b982584 Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121)
* Keyman for Windows 10.0 Open Source

* Squashed 'windows/src/ext/jedi/jedi/' content from commit f444ad2

git-subtree-dir: windows/src/ext/jedi/jedi
git-subtree-split: f444ad2da4693851e523f1ea6bd541f701904c24

* Squashed 'windows/src/ext/jedi/jcl/' content from commit d63d3c9fd

git-subtree-dir: windows/src/ext/jedi/jcl
git-subtree-split: d63d3c9fd9ff84efdd8159084ec6a60313644243

* Squashed 'windows/src/ext/jedi/jvcl/' content from commit bee19f3b4

git-subtree-dir: windows/src/ext/jedi/jvcl
git-subtree-split: bee19f3b46909fde2fa92c06cd2706f41d99f6c3

* Add required .res files

* Add required .res files

* Add docbook files (forced)

* Add required libxslt

* Add required jedi files

* Add installation files

* Tweak .gitignore for open

* CI

* Remove KMW from Developer source (#122)

* Remove KMW from Developer source (copies during build)

* Remove KMW from Developer source (copies during build)

* Remove KMW from Developer source (copies during build)

* Fixup release build and copy license, readme from kmw during build

* Remove obsolete build help documentation

* Keyman Engine 10 on Windows regression for shift states (#129)

* Improve #128 -- cleaner debug messages

* Fixes #127, shift state now resets correctly; and more work for #128

* Fixes #130 (#131)
2017-07-25 10:53:06 +07:00

124 lines
3.7 KiB
C++

/*
Name: syskbdnt
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Create Date: 22 Jan 2007
Modified Date: 6 Feb 2015
Authors: mcdurdin
Related Files:
Dependencies:
Bugs:
Todo:
Notes:
History: 22 Jan 2007 - mcdurdin - Don't translate any number pad keys
13 Jul 2007 - mcdurdin - I911 - Fix for Ctrl+BKSP
10 Sep 2008 - mcdurdin - I1635 - mnemonic layouts on x64 fail
11 Mar 2009 - mcdurdin - I1894 - Fix threading bugs introduced in I1888
30 Nov 2009 - mcdurdin - I934 - Prep for x64 - change UINT to WORD for vkeys
30 Nov 2009 - mcdurdin - I2155 - Fix crash when RALT pressed on wow64
11 Dec 2009 - mcdurdin - I934 - x64 - Initial version
12 Mar 2010 - mcdurdin - I934 - x64 - Complete
12 Mar 2010 - mcdurdin - I2229 - Remove hints and warnings
04 May 2010 - mcdurdin - I2351 - Robustness - verify _td return value
16 Apr 2014 - mcdurdin - I4169 - V9.0 - Mnemonic layouts should be recompiled to positional based on user-selected base keyboard
03 Feb 2015 - mcdurdin - I4582 - V9.0 - Most underlying layout code in Keyman32 is now obsolete and needs to be removed
06 Feb 2015 - mcdurdin - I4583 - V9.0 - Remove altgr lookup test from keyman32 and put it into the registry
*/
// I4169 // I4582 // I4583
////////////////////////////////////////////////////////////////////////////
//
// Use Windows NT/2000 keyboard DLLs for mapping virtual keys to characters
//
////////////////////////////////////////////////////////////////////////////
#include "keyman64.h"
#include "kbd.h" /* DDK kbdlayout */
#ifndef _WIN64
extern BOOL KeyboardGivesCtrlRAltForRAlt_NT_x64();
extern BOOL IsWow64();
#endif
typedef PKBDTABLES (WINAPI *PKBDLAYERDESCRIPTORFUNC)(VOID);
static WCHAR PreviousDeadkey_NT = 0;
static HKL ActiveHKL_NT = 0;
static WORD VkToVkByChar_NT[256] = {0};
static HMODULE hKbdLibrary = NULL;
static PKBDTABLES KbdTables = NULL;
BOOL LoadNewLibrary()
{
char buf[128], buf2[KL_NAMELENGTH+1];
memset(VkToVkByChar_NT, 0, sizeof(VkToVkByChar_NT));
if(hKbdLibrary) FreeLibrary(hKbdLibrary);
PreviousDeadkey_NT = 0;
RegistryReadOnly *r = new RegistryReadOnly(HKEY_LOCAL_MACHINE);
__try
{
GetKeyboardLayoutName(buf2);
wsprintf(buf, "System\\CurrentControlSet\\Control\\keyboard layouts\\%s", buf2);
if(r->OpenKeyReadOnly(buf))
{
if(r->ReadString("Layout File", buf, 32))
{
hKbdLibrary = LoadLibrary(buf);
if(!hKbdLibrary)
{
SendDebugMessageFormat(GetFocus(), sdmKeyboard, 0, "LoadNewLibrary: Exit -- could not load library");
return FALSE;
}
PKBDLAYERDESCRIPTORFUNC KbdLayerDescriptorFunc = (PKBDLAYERDESCRIPTORFUNC) GetProcAddress(hKbdLibrary, "KbdLayerDescriptor");
if(KbdLayerDescriptorFunc)
{
KbdTables = (*KbdLayerDescriptorFunc)();
if(KbdTables)
return TRUE;
}
FreeLibrary(hKbdLibrary);
}
}
hKbdLibrary = NULL;
KbdTables = NULL;
}
__finally
{
delete r;
}
SendDebugMessageFormat(GetFocus(), sdmKeyboard, 0, "LoadNewLibrary: Exit -- failed to find function");
return FALSE;
}
BOOL KeyboardGivesCtrlRAltForRAlt_NT()
{
#ifndef _WIN64
if(IsWow64()) return KeyboardGivesCtrlRAltForRAlt_NT_x64(); // I2155
#endif
HKL hkl = GetKeyboardLayout(0);
/* Find the appropriate keyboard tables */
if(hkl != ActiveHKL_NT)
{
ActiveHKL_NT = hkl;
LoadNewLibrary();
}
if(!KbdTables) /* Could not load keyboard DLL */
return FALSE;
return (KbdTables->fLocaleFlags & 0x1) ? TRUE : FALSE;
}