static HHOOK hook = 0;
static HWND target_wnd = 0;
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
+
static int is_system_hotkey(int vkCode) {
switch (vkCode) {
case VK_LWIN:
thread = NULL;
}
+// Layout independent keys
static const int vkey_map[][3] = {
{ VK_CANCEL, NoSymbol, XK_Break },
{ VK_BACK, XK_BackSpace, NoSymbol },
{ VK_MEDIA_PLAY_PAUSE, NoSymbol, XF86XK_AudioPlay },
{ VK_LAUNCH_MAIL, NoSymbol, XF86XK_Mail },
{ VK_LAUNCH_APP2, NoSymbol, XF86XK_Calculator },
- // Japanese keyboard support
+};
+
+// Layout dependent keys, but without useful symbols
+
+// Japanese
+static const int vkey_map_jp[][3] = {
{ VK_OEM_ATTN, XK_Eisu_toggle, NoSymbol },
{ VK_OEM_FINISH, XK_Katakana, NoSymbol },
{ VK_OEM_COPY, XK_Hiragana, NoSymbol },
{ VK_OEM_BACKTAB, XK_Romaji, NoSymbol },
};
+static int lookup_vkey_map(UINT vkey, int extended, const int map[][3], size_t size)
+{
+ size_t i;
+
+ for (i = 0;i < size;i++) {
+ if (vkey != map[i][0])
+ continue;
+
+ if (extended)
+ return map[i][2];
+ else
+ return map[i][1];
+ }
+
+ return NoSymbol;
+}
+
int win32_vkey_to_keysym(UINT vkey, int extended)
{
- int i;
+ HKL layout;
+ WORD lang, primary_lang;
BYTE state[256];
int ret;
// Start with keys that either don't generate a symbol, or
// generate the same symbol as some other key.
- for (i = 0;i < sizeof(vkey_map)/sizeof(vkey_map[0]);i++) {
- if (vkey == vkey_map[i][0]) {
- if (extended)
- return vkey_map[i][2];
- else
- return vkey_map[i][1];
- }
+
+ ret = lookup_vkey_map(vkey, extended, vkey_map, ARRAY_SIZE(vkey_map));
+ if (ret != NoSymbol)
+ return ret;
+
+ layout = GetKeyboardLayout(0);
+ lang = LOWORD(layout);
+ primary_lang = PRIMARYLANGID(lang);
+
+ if (primary_lang == LANG_JAPANESE) {
+ ret = lookup_vkey_map(vkey, extended,
+ vkey_map_jp, ARRAY_SIZE(vkey_map_jp));
+ if (ret != NoSymbol)
+ return ret;
}
// Windows is not consistent in which virtual key it uses for