void UpdateData(HWND hDlg) { WCHAR buf[KL_NAMELENGTH]; WCHAR buf2[512]; HWND hList; HKL *klList, hKl; int n, i,j; GetKeyboardLayoutName(buf); swprintf(buf2, L"Active: %s (%x)", buf, GetKeyboardLayout(0)); SetWindowText(GetDlgItem(hDlg, IDC_ACTIVE), buf2); hList = GetDlgItem(hDlg, IDC_LIST); SendMessage(hList, LB_RESETCONTENT, 0, 0); n = GetKlList(&klList); hKl = GetKeyboardLayout(0); for(i = 0; i < n; i++) { swprintf(buf, L"%x", klList[i] ); j = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM) buf); SendMessage(hList, LB_SETITEMDATA, j, (LPARAM) klList[i]); if(klList[i] == hKl) SendMessage(hList, LB_SETCURSEL, j, 0); } FreeKlList(klList); }
SInt32 CMSWindowsKeyState::pollActiveGroup() const { // determine the thread that'll receive this event HWND targetWindow = GetForegroundWindow(); DWORD targetThread = GetWindowThreadProcessId(targetWindow, NULL); // get keyboard layout for the thread HKL hkl = GetKeyboardLayout(targetThread); if (!hkl) { // GetKeyboardLayout failed. Maybe targetWindow is a console window. // We're getting the keyboard layout of the desktop instead. targetWindow = GetDesktopWindow(); targetThread = GetWindowThreadProcessId(targetWindow, NULL); hkl = GetKeyboardLayout(targetThread); } // get group GroupMap::const_iterator i = m_groupMap.find(hkl); if (i == m_groupMap.end()) { LOG((CLOG_DEBUG1 "can't find keyboard layout %08x", hkl)); return 0; } return i->second; }
LRESULT TransConvertList( HIMC hImc, LPIMESTRUCT lpIme) { LPSTR lpSrc; LPSTR lpDst; HGLOBAL hCandList; LPCANDIDATELIST lpCandList; LPSTR lpCandStr; UINT i, uBufLen; LRESULT lRet = 0; lpSrc = lpSource(lpIme); lpDst = lpDest(lpIme); uBufLen = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc, NULL, 0, GCL_CONVERSION); if (uBufLen) { hCandList = GlobalAlloc(GHND, uBufLen); lpCandList = (LPCANDIDATELIST)GlobalLock(hCandList); lRet = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc, lpCandList, uBufLen, GCL_CONVERSION); for (i = 0; i < lpCandList->dwCount; i++) { lpCandStr = (LPSTR)lpCandList + lpCandList->dwOffset[i]; *lpDst++ = *lpCandStr++; *lpDst++ = *lpCandStr++; } *lpDst = '\0'; lpIme->wCount = (WORD)lpCandList->dwCount * 2; GlobalUnlock(hCandList); GlobalFree(hCandList); } return (lRet); }
CString VkToString( DWORD vk ) { UINT vsc = MapVirtualKeyEx( vk & 0x7fffffffUL, MAPVK_VK_TO_VSC, GetKeyboardLayout( 0 ) ); if ( ! vsc ) { return CString( ); } BYTE keyState[256] = { 0, }; wchar_t keyBuf[8] = { 0, }; if ( 0 != ( vk & 0x80000000 ) ) { keyState[VK_SHIFT] = 0x80; } ToUnicodeEx( vk, vsc, keyState, keyBuf, 256, 0, GetKeyboardLayout( 0 ) ); return CString( keyBuf ); }
void CKeyboardLayout::InitKeyboardLayout() { m_ToolTip.Create(this, TTS_ALWAYSTIP | TTS_NOPREFIX); m_ToolTip.SetMaxTipWidth(0x100); // Enable multiline LoadScanCodeMap(m_HkeyType); for (int i = 0; i < MAX_KEYBOARD_LAYOUT; ++i) { if (!GetDlgItem(m_KeyboardLayouts[i].nBaseControlID) || !GetDlgItem(m_KeyboardLayouts[i].nCurrentControlID)) { continue; } m_KeyboardLayouts[i].pBaseKey = new CKey(m_KeyboardLayouts[i].nBaseControlID, NORMAL_KEY, m_HkeyType); m_KeyboardLayouts[i].pBaseKey->SubclassDlgItem(m_KeyboardLayouts[i].nBaseControlID, this); m_ToolTip.AddTool(GetDlgItem(m_KeyboardLayouts[i].nBaseControlID), GetToolTipID(m_KeyboardLayouts[i].nToolTipID)); m_KeyboardLayouts[i].pCurrentKey = new CKey(m_KeyboardLayouts[i].nCurrentControlID, ORIGINAL_KEY, m_HkeyType); m_KeyboardLayouts[i].pCurrentKey->SubclassDlgItem(m_KeyboardLayouts[i].nCurrentControlID, this); m_ToolTip.AddTool(GetDlgItem(m_KeyboardLayouts[i].nCurrentControlID), GetToolTipID(m_KeyboardLayouts[i].nToolTipID)); ScanCode current = {'\0'}; if (GetScanCodeMap(m_HkeyType, m_KeyboardLayouts[i].scancode, ¤t)) { m_KeyboardLayouts[i].pCurrentKey->SetKeyType(REMAPPED_KEY); CString szWindowText; GetDlgItem(GetBaseControlID(current))->GetWindowText(szWindowText); GetDlgItem(m_KeyboardLayouts[i].nCurrentControlID)->SetWindowText(szWindowText); KeyboardLayout *pKeyboardLayout = GetKeyboardLayout(GetBaseControlID(current)); if (pKeyboardLayout) { m_ToolTip.UpdateTipText(GetToolTipID(pKeyboardLayout->nToolTipID), GetDlgItem(m_KeyboardLayouts[i].nCurrentControlID)); } } } }
CKeySend::CKeySend(bool bForceOldMethod, unsigned defaultDelay) : m_delayMS(defaultDelay) { if (bFirst) { cinput.type = INPUT_KEYBOARD; cinput.ki.wVk = 0; cinput.ki.wScan = 0; cinput.ki.dwFlags = 0; cinput.ki.time = 0; cinput.ki.dwExtraInfo = 0; bFirst = false; } m_impl = new CKeySendImpl; m_impl->m_delay = m_delayMS; // We want to use keybd_event (OldSendChar) for Win2K & older, // SendInput (NewSendChar) for newer versions. if (bForceOldMethod) m_impl->m_isOldOS = true; else { m_impl->m_isOldOS = !pws_os::IsWindowsVistaOrGreater(); } // get the locale of the current thread. // we are assuming that all window and threading in the // current users desktop have the same locale. m_impl->m_hlocale = GetKeyboardLayout(0); }
LCID Applet::GetLocaleId(DWORD threadId) { HKL hkl = GetKeyboardLayout(threadId); DWORD lgid = LOWORD(hkl); return MAKELCID(lgid, SORT_DEFAULT); }
void _gdk_windowing_init (void) { gchar buf[10]; if (getenv ("GDK_IGNORE_WINTAB") != NULL) _gdk_input_ignore_wintab = TRUE; else if (getenv ("GDK_USE_WINTAB") != NULL) _gdk_input_ignore_wintab = FALSE; if (gdk_synchronize) GdiSetBatchLimit (1); _gdk_app_hmodule = GetModuleHandle (NULL); _gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL); _gdk_input_locale = GetKeyboardLayout (0); _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale); GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, buf, sizeof (buf)); _gdk_input_codepage = atoi (buf); GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n", _gdk_input_locale, _gdk_input_codepage)); CoInitialize (NULL); _gdk_selection = gdk_atom_intern_static_string ("GDK_SELECTION"); _wm_transient_for = gdk_atom_intern_static_string ("WM_TRANSIENT_FOR"); _targets = gdk_atom_intern_static_string ("TARGETS"); _delete = gdk_atom_intern_static_string ("DELETE"); _save_targets = gdk_atom_intern_static_string ("SAVE_TARGETS"); _utf8_string = gdk_atom_intern_static_string ("UTF8_STRING"); _text = gdk_atom_intern_static_string ("TEXT"); _compound_text = gdk_atom_intern_static_string ("COMPOUND_TEXT"); _text_uri_list = gdk_atom_intern_static_string ("text/uri-list"); _text_html = gdk_atom_intern_static_string ("text/html"); _image_png = gdk_atom_intern_static_string ("image/png"); _image_jpeg = gdk_atom_intern_static_string ("image/jpeg"); _image_bmp = gdk_atom_intern_static_string ("image/bmp"); _image_gif = gdk_atom_intern_static_string ("image/gif"); _local_dnd = gdk_atom_intern_static_string ("LocalDndSelection"); _gdk_win32_dropfiles = gdk_atom_intern_static_string ("DROPFILES_DND"); _gdk_ole2_dnd = gdk_atom_intern_static_string ("OLE2_DND"); /* MS Office 2007, at least, offers images in common file formats * using clipboard format names like "PNG" and "JFIF". So we follow * the lead and map the GDK target name "image/png" to the clipboard * format name "PNG" etc. */ _cf_png = RegisterClipboardFormat ("PNG"); _cf_jfif = RegisterClipboardFormat ("JFIF"); _cf_gif = RegisterClipboardFormat ("GIF"); _cf_url = RegisterClipboardFormat ("UniformResourceLocatorW"); _cf_html_format = RegisterClipboardFormat ("HTML Format"); _cf_text_html = RegisterClipboardFormat ("text/html"); _gdk_win32_selection_init (); }
int iupwinKeyDecode(int wincode) { HKL k; int i, count; k = GetKeyboardLayout(0); if ((int)HIWORD(k) == 0x0416) /* ABNT */ { int abnt_count = sizeof(keytable_abnt)/sizeof(keytable_abnt[0]); for (i = 0; i < abnt_count; i++) { if (keytable_abnt[i].wincode == wincode) return winKeyMap2Iup(keytable_abnt, i); } } count = sizeof(winkey_map)/sizeof(winkey_map[0]); for (i = 0; i < count; i++) { if (winkey_map[i].wincode == wincode) return winKeyMap2Iup(winkey_map, i); } return 0; }
HKL GetLayoutOfText(LPCTSTR ptszInText) { HKL hklCurLay = hklLayouts[0]; LPTSTR ptszKeybBuff = ptszLayStrings[0]; DWORD dwMaxSymbols = 0, dwTemp = 0; for (DWORD j = 0; j < _tcslen(ptszInText); j++) if (_tcschr(ptszKeybBuff, ptszInText[j]) != NULL) ++dwMaxSymbols; for (DWORD i = 1; i < bLayNum; i++) { ptszKeybBuff = ptszLayStrings[i]; DWORD dwCountSymbols = 0; for (DWORD j = 0; j<_tcslen(ptszInText); j++) if (_tcschr(ptszKeybBuff, ptszInText[j]) != NULL) ++dwCountSymbols; if (dwCountSymbols == dwMaxSymbols) dwTemp = dwCountSymbols; else if (dwCountSymbols>dwMaxSymbols) { dwMaxSymbols = dwCountSymbols; hklCurLay = hklLayouts[i]; } } if (dwMaxSymbols == dwTemp) hklCurLay = GetKeyboardLayout(0); return hklCurLay; }
void strSetCurKeyboard(void) { udword keyboard; if (keyboard = GetKeyboardLayout(0)) { if (PRIMARYLANGID(keyboard)==LANG_ENGLISH) { strCurKeyboardLanguage = languageEnglish; } else if (PRIMARYLANGID(keyboard)==LANG_FRENCH) { strCurKeyboardLanguage = languageFrench; } else if (PRIMARYLANGID(keyboard)==LANG_GERMAN) { strCurKeyboardLanguage = languageGerman; } else if (PRIMARYLANGID(keyboard)==LANG_SPANISH) { strCurKeyboardLanguage = languageSpanish; } else if (PRIMARYLANGID(keyboard)==LANG_ITALIAN) { strCurKeyboardLanguage = languageItalian; } } else strCurKeyboardLanguage = languageEnglish; }
CKeySend::CKeySend(bool bForceOldMethod) : m_delayMS(10) { if (bFirst) { cinput.type = INPUT_KEYBOARD; cinput.ki.wVk = 0; cinput.ki.wScan = 0; cinput.ki.dwFlags = 0; cinput.ki.time = 0; cinput.ki.dwExtraInfo = 0; bFirst = false; } m_impl = new CKeySendImpl; m_impl->m_delay = m_delayMS; // We want to use keybd_event (OldSendChar) for Win2K & older, // SendInput (NewSendChar) for newer versions. if (bForceOldMethod) m_impl->m_isOldOS = true; else { DWORD majorVersion, minorVersion; pws_os::getosversion(majorVersion, minorVersion); m_impl->m_isOldOS = ((majorVersion <= 4) || (majorVersion == 5 && minorVersion == 0)); } // get the locale of the current thread. // we are assuming that all window and threading in the // current users desktop have the same locale. m_impl->m_hlocale = GetKeyboardLayout(0); }
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { //fs_log("WndProc %d\n", message); HRAWINPUT raw_input_handle; switch (message) { case WM_INPUTLANGCHANGE: g_keyboard_layout = GetKeyboardLayout(0); break; case WM_INPUT: raw_input_handle = (HRAWINPUT) lparam; /* unsigned int size; if (GetRawInputData(raw_input_handle, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) != -1) { void *data = malloc(size); if (GetRawInputData(raw_input_handle, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)) != -1) { process_input(data); } free(data); } */ unsigned int size = RAW_INPUT_MAX_SIZE; if (GetRawInputData(raw_input_handle, RID_INPUT, &g_raw_input_data, &size, sizeof(RAWINPUTHEADER)) != -1) { process_input(&g_raw_input_data); } // must call DefWindowProc according to http://msdn.microsoft.com/ // en-us/library/windows/desktop/ms645590(v=vs.85).aspx return DefWindowProc(hwnd, message, wparam, lparam); } return CallWindowProc(g_wndproc, hwnd, message, wparam, lparam); }
/** * Show the on-screen keyboard (osk) associated with a given textbox * @param parent pointer to the Window where this keyboard originated from * @param button widget number of parent's textbox */ void ShowOnScreenKeyboard(Window *parent, int button) { DeleteWindowById(WC_OSK, 0); GetKeyboardLayout(); new OskWindow(&_osk_desc, parent, button); }
static UInt8 _dx2vk(UINT dx){ if (dx >= VK_TABLE_SIZE) return NOKEY; UInt8 vkCode = NOKEY; HKL kbLayout = GetKeyboardLayout(0); vkCode = MapVirtualKeyEx(dx, 3, kbLayout); if (!vkCode) { switch (dx) { DX2VK(DIVIDE); DX2VK(RCONTROL); DX2VK(RMENU); DX2VK(HOME); DX2VK(PRIOR); DX2VK(UP); DX2VK(DOWN); DX2VK(LEFT); DX2VK(RIGHT); DX2VK(END); DX2VK(NEXT); DX2VK(INSERT); DX2VK(DELETE); case DIK_NUMPADENTER: vkCode = VK_SEPARATOR; break; default: vkCode = NOKEY; } } return vkCode; }
// &SetImeString static void funcSetImeString(HWND i_hwnd, int i_size) { _TCHAR *buf = new _TCHAR(i_size); DWORD len = 0; _TCHAR ImeDesc[GANA_MAX_ATOM_LENGTH]; UINT ImeDescLen; DWORD error; DWORD denom = 1; HANDLE hPipe = CreateFile(addSessionId(HOOK_PIPE_NAME).c_str(), GENERIC_READ, FILE_SHARE_READ, (SECURITY_ATTRIBUTES *)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL); error = ReadFile(hPipe, buf, i_size, &len, NULL); CloseHandle(hPipe); ImeDescLen = ImmGetDescription(GetKeyboardLayout(0), ImeDesc, sizeof(ImeDesc)); if (_tcsncmp(ImeDesc, _T("SKKIME"), ImeDescLen) > 0) denom = sizeof(_TCHAR); HIMC hIMC = ImmGetContext(i_hwnd); if (hIMC == INVALID_HANDLE_VALUE) return; int status = ImmGetOpenStatus(hIMC); ImmSetCompositionString(hIMC, SCS_SETSTR, buf, len / denom, NULL, 0); delete buf; ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0); if (!status) ImmSetOpenStatus(hIMC, status); ImmReleaseContext(i_hwnd, hIMC); }
/** * Launches Awesomenauts, registers the chat binds and listens for key events. */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Process* awsmProcess = new Process(); // Load the config file data. INIReader* reader = new INIReader(BLABL_CONFIG); if (reader->ParseError() < 0) { std::cerr << "ERROR: Failed to parse config file." << std::endl; return 1; } // Launch Awesomenauts. const char* awsmBin = reader->Get("Awesomenauts", "Bin", DEFAULT_BIN).c_str(); const char* awsmDir = reader->Get("Awesomenauts", "Dir", DEFAULT_DIR).c_str(); if (!awsmProcess->Launch(awsmBin, awsmDir)) { std::cerr << "ERROR: Failed to create process." << std::endl; return 1; } // Load the bindings and listen for hot key presses while Awesomenauts runs. KeyListener* awsmListener = new KeyListener(GetKeyboardLayout(0)); awsmListener->LoadFromFile(reader); delete reader; while (awsmProcess->IsRunning()) awsmListener->ProcessInput(); delete awsmProcess; delete awsmListener; return 0; }
/* returns host keyboard mapping. used to initialize the keyboard map when starting with a black (default) config, so an educated guess works good enough most of the time :) FIXME: add more languages, constants are defined in winnt.h https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693%28v=vs.85%29.aspx */ int kbd_arch_get_host_mapping(void) { int n; int maps[KBD_MAPPING_NUM] = { KBD_MAPPING_US, KBD_MAPPING_UK, KBD_MAPPING_DE, KBD_MAPPING_DA, KBD_MAPPING_NO, KBD_MAPPING_FI, KBD_MAPPING_IT }; int langids[KBD_MAPPING_NUM] = { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_DANISH, SUBLANG_DANISH_DENMARK), MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL), MAKELANGID(LANG_FINNISH, SUBLANG_FINNISH_FINLAND), MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN) }; int lang = (int)GetKeyboardLayout(0); /* try full match first */ lang &= 0xffff; /* lower 16 bit contain the language id */ for (n = 0; n < KBD_MAPPING_NUM; n++) { if (lang == langids[n]) { return maps[n]; } } /* try only primary language */ lang &= 0x3ff; /* lower 10 bit contain the primary language id */ for (n = 0; n < KBD_MAPPING_NUM; n++) { if (lang == (langids[n] & 0x3ff)) { return maps[n]; } } return KBD_MAPPING_US; }
UINT TranslateToUnicode (WORD *uVKey, LPBYTE GlobalKeyStates){ BYTE KeyStates[256]; UINT USvk = 0; GetKeyboardState(KeyStates); KeyStates[VK_CONTROL] = KeyStates[VK_MENU ] = KeyStates[VK_LMENU] = KeyStates[VK_RMENU] = 0; if (!klf.layout.trackCaps) KeyStates[VK_CAPITAL] = 0; WCHAR TransedChar = NULL; UINT ScanCode = MapVirtualKey(*uVKey, MAPVK_VK_TO_VSC); if (!ScanCode) return false; if (klf.layout.posBased==true && GetKeyboardLayout(0) != (HKL)0x04090409){ USvk = ScancodeToVirtualkey(ScanCode); if (USvk != *uVKey && USvk <= 255){ GlobalKeyStates[USvk] = KeyStates[USvk] = KeyStates[*uVKey]; GlobalKeyStates[*uVKey] = KeyStates[*uVKey] = 0x00; *uVKey = USvk; } }else { USvk = *uVKey ; } int Return = ToUnicodeEx(*uVKey, ScanCode, KeyStates, &TransedChar, 1, 0, hkl); if (!Return) return false; if (TransedChar > 33 || TransedChar < 126) *uVKey = TransedChar; else {return false;} return USvk; }
i32 CKeyboard::Init() { //Get default keyboard localization m_WinHKL = GetKeyboardLayout( 0 ); return XST_OK; }
/** * Sends a char using emulated keyboard input * * This works for most cases, but not for dead keys etc **/ void sendChar(TCHAR key, KBDLLHOOKSTRUCT keyInfo) { SHORT keyScanResult = VkKeyScanEx(key, GetKeyboardLayout(0)); keyInfo.vkCode = keyScanResult; char modifiers = keyScanResult >> 8; bool shift = ((modifiers & 1) != 0); bool alt = ((modifiers & 2) != 0); bool ctrl = ((modifiers & 4) != 0); bool altgr = alt && ctrl; if (altgr) { ctrl = false; alt = false; } if (altgr) keybd_event(VK_RMENU, 0, 0, 0); if (ctrl) keybd_event(VK_CONTROL, 0, 0, 0); if (alt) keybd_event(VK_MENU, 0, 0, 0); // ALT if (shift) keybd_event(VK_SHIFT, 0, 0, 0); keybd_event(keyInfo.vkCode, keyInfo.scanCode, keyInfo.flags, keyInfo.dwExtraInfo); if (altgr) keybd_event(VK_RMENU, 0, KEYEVENTF_KEYUP, 0); if (ctrl) keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); if (alt) keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); // ALT if (shift) keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); }
void CImeView::InitIme(HWND hwnd) { char ga[] = "가"; SIZE size; HFONT hFont; LOGFONT lf; if(hwnd) m_hWnd = hwnd; hFont = (HFONT)SendMessage(m_hWnd,WM_GETFONT, 0, 0); if (hFont) { if (GetObject(hFont, sizeof(LOGFONT), &lf)) { SetCompositionFont(&lf); } } //m_hKeyWnd = hwnd; m_hKeyLayout = GetKeyboardLayout(0); // 0 means Current thread m_property = ImmGetProperty(m_hKeyLayout, IGP_PROPERTY); for (int i = 0; i < MAX_LISTCAND; i++) { m_hwndCand[i] = NULL; m_CandList[i] = NULL; } return; HDC hDC = ::GetDC(m_hWnd); HFONT hScrFont = (HFONT)GetStockObject(SYSTEM_FIXED_FONT); HFONT hOldFont = (HFONT)SelectObject(hDC, hScrFont); GetTextExtentPoint(hDC, (LPSTR)&ga, 2, &size); SelectObject(hDC, hOldFont); ::ReleaseDC(m_hWnd, hDC); m_charWidth = size.cx / 2; m_charHeight = size.cy; }
string Utilities::GetCurrentKeyboardLayout() { #if defined( WIN32 ) WORD latoutKey = LOWORD(GetKeyboardLayout(0)); //get current layout. switch(latoutKey) { case 1040: return string("it"); case 1031: return string("de"); case 1078: return string("af"); case 1052: return string("sq"); case 1025: return string("ar"); case 1069: return string("eu"); case 1059: return string("be"); case 1026: return string("bg"); case 1027: return string("ca"); case 1028: return string("ch"); case 1029: return string("cs"); case 1030: return string("da"); case 1043: return string("nl"); case 1033: return string("us"); case 1061: return string("et"); case 1080: return string("fo"); case 1065: return string("fa"); case 1035: return string("fi"); case 1036: return string("fr"); case 1032: return string("el"); case 1037: return string("he"); case 1038: return string("hu"); case 1039: return string("is"); case 1057: return string("in"); case 1041: return string("jp"); case 1042: return string("ko"); case 1062: return string("lv"); case 1063: return string("lt"); case 1044: return string("no"); case 1045: return string("pl"); case 1046: return string("pt"); case 1048: return string("ro"); case 1049: return string("ru"); case 1050: return string("hr"); case 1051: return string("sk"); case 1060: return string("sl"); case 1034: return string("es"); case 1053: return string("sv"); case 1054: return string("th"); case 1055: return string("tr"); case 1066: return string("vi"); case 2057: return string("uk"); default: return ""; }; #else XInterface xInterface( NULL ); string sTmp = xInterface.GetKeyboardLayout().c_str(); return sTmp; #endif }
void ConvertKeyToCurrentKeyboard(char* sNewKey, char* sOldKey, int nNewKeyMaxSize) { if (_mbstrlen(sOldKey) == 1) { HKL nDefaultKeyboard = GetKeyboardLayout(0); SHORT nCharCode = sOldKey[0]; if ((nCharCode > 0) && (nCharCode <= 255)) { SHORT nScanCode = g_pEnglishCharToScanCodeTable[nCharCode]; if (nScanCode != -1) { SHORT nKeyCode2 = MapVirtualKeyEx(nScanCode & 0xff, 1, nDefaultKeyboard); if (nKeyCode2 != -1) { UINT nNewChar = MapVirtualKeyEx( nKeyCode2 & 0xff, 2, nDefaultKeyboard); if (nNewChar != 0) { sNewKey[0] = (char)nNewChar; sNewKey[1] = '\0'; return; } } } } } _mbsncpy((unsigned char*)sNewKey, (const unsigned char*)sOldKey, nNewKeyMaxSize); sNewKey[nNewKeyMaxSize-1] = '\0'; }
UInt32 MapScanCodeToChar( UINT scanCode , BYTE *charCode ) { HKL hklKeyboardLayout = GetKeyboardLayout(0); // 0 means current thread // This seemingly cannot fail // If this value is cached then the application must respond to WM_INPUTLANGCHANGE /* * Notes on second arg beeing 2: * uCode is a virtual-key code and is translated into an unshifted character value in * the low-order word of the return value. Dead keys (diacritics) are indicated by * setting the top bit of the return value. If there is no translation, the function returns 0. */ UINT uiCharCode = MapVirtualKeyEx( scanCode , 2 , // Convert scan code to char code hklKeyboardLayout ); if( 0 == uiCharCode ) { // Error converting to a char return 0; } *charCode = ((BYTE)uiCharCode); return 1; }
/** * Utility function for converting from virtual DI key values into * keyboard scancodes. * * @return 0 on failure 1 on success */ UInt32 MapDIKeyToScancode( UINT keyCode , UINT *scanCode ) { HKL hklKeyboardLayout = GetKeyboardLayout(0); // 0 means current thread // This seemingly cannot fail // If this value is cached then the application must respond to WM_INPUTLANGCHANGE /* * Notes on second arg beeing 0: * uCode is a virtual-key code and is translated into a scan code. * If it is a virtual-key code that does not distinguish between left- and right-hand keys, * the left-hand scan code is returned. If there is no translation, the function returns 0. */ UINT uiScanCode = MapVirtualKeyEx( keyCode , 0 , // Convert DIK_ code to scan code hklKeyboardLayout ); if( 0 == uiScanCode ) { // Error converting to a scancode return 0; } *scanCode = uiScanCode; return 1; }
UINT VkToVsc( DWORD vk ) { UINT vsc = MapVirtualKeyEx( vk & 0x7fffffffUL, MAPVK_VK_TO_VSC, GetKeyboardLayout( 0 ) ); if ( 0 == vsc ) return 0; return MAKELONG( 1, vsc ); }
void SetDefaultKeyMap(DefaultMaps dmap, bool replace) { switch (dmap) { case DEFAULT_MAPPING_KEYBOARD: { bool azerty = false; bool qwertz = false; #if defined(SDL) char q, w, y; q = SDL_GetKeyFromScancode(SDL_SCANCODE_Q); w = SDL_GetKeyFromScancode(SDL_SCANCODE_W); y = SDL_GetKeyFromScancode(SDL_SCANCODE_Y); if (q == 'a' && w == 'z' && y == 'y') azerty = true; else if (q == 'q' && w == 'w' && y == 'z') qwertz = true; #elif defined(USING_WIN_UI) HKL localeId = GetKeyboardLayout(0); // TODO: Is this list complete enough? switch ((int)(intptr_t)localeId & 0xFFFF) { case 0x407: qwertz = true; break; case 0x040c: case 0x080c: case 0x1009: azerty = true; break; default: break; } #endif if (azerty) { SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultAzertyKeyboardKeyMap, ARRAY_SIZE(defaultAzertyKeyboardKeyMap), replace); } else if (qwertz) { SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertzKeyboardKeyMap, ARRAY_SIZE(defaultQwertzKeyboardKeyMap), replace); } else { SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertyKeyboardKeyMap, ARRAY_SIZE(defaultQwertyKeyboardKeyMap), replace); } } break; case DEFAULT_MAPPING_X360: SetDefaultKeyMap(DEVICE_ID_X360_0, default360KeyMap, ARRAY_SIZE(default360KeyMap), replace); break; case DEFAULT_MAPPING_SHIELD: SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultShieldKeyMap, ARRAY_SIZE(defaultShieldKeyMap), replace); break; case DEFAULT_MAPPING_PAD: SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultPadMap, ARRAY_SIZE(defaultPadMap), replace); break; case DEFAULT_MAPPING_OUYA: SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultOuyaMap, ARRAY_SIZE(defaultOuyaMap), replace); break; case DEFAULT_MAPPING_XPERIA_PLAY: SetDefaultKeyMap(DEVICE_ID_DEFAULT, defaultXperiaPlay, ARRAY_SIZE(defaultXperiaPlay), replace); break; } UpdateNativeMenuKeys(); }
bool KeyboardDevice::doKeyAction(Action action, int nativeKey, bool alterPressedKeys) { bool result = true; #ifdef Q_OS_UNIX KeyCode keyCode = XKeysymToKeycode(QX11Info::display(), nativeKey); if(action == Press || action == Trigger) result &= XTestFakeKeyEvent(QX11Info::display(), keyCode, True, CurrentTime); if(action == Release || action == Trigger) result &= XTestFakeKeyEvent(QX11Info::display(), keyCode, False, CurrentTime); XFlush(QX11Info::display()); #endif #ifdef Q_OS_WIN INPUT input; SecureZeroMemory(&input, sizeof(INPUT)); input.type = INPUT_KEYBOARD; switch(mType) { case Win32: { input.ki.wVk = nativeKey; HKL keyboardLayout = GetKeyboardLayout(0); input.ki.wScan = MapVirtualKeyEx(nativeKey, MAPVK_VK_TO_VSC, keyboardLayout); if(extendedKeys.count(nativeKey) > 0) input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; } break; case DirectX: input.ki.wVk = 0; input.ki.wScan = ActionTools::KeyMapper::toDirectXKey(nativeKey); break; } if(action == Press || action == Trigger) result &= (SendInput(1, &input, sizeof(INPUT)) != 0); if(action == Release || action == Trigger) { input.ki.dwFlags |= KEYEVENTF_KEYUP; result &= (SendInput(1, &input, sizeof(INPUT)) != 0); } #endif if(alterPressedKeys) { if(action == Press) mPressedKeys.insert(nativeKey); else if(action == Release) mPressedKeys.remove(nativeKey); } return result; }
BOOL WINAPI ImmActivateLayout( HKL hSelKL) { HKL hUnSelKL; HWND hWndDefaultIme; SCE sce; hUnSelKL = GetKeyboardLayout(0); /* * If already the current active keyboard layout, do nothing. */ if (hUnSelKL == hSelKL) return TRUE; #ifdef LATER // Do EnumWndProcIMEUnselect() for old app. support here. #endif ImmLoadIME(hSelKL); /* * CPS_CANCEL all strings for every input context assoicated * to window(s) created by this thread. Starting from SUR, * we only assoicate input context to window created by the * same thread. Just do an EnumInputContext here for speed. */ EnumInputContext(GetCurrentThreadId(), (IMCENUMPROC)NotifyIMEProc, 0L); hWndDefaultIme = ImmGetDefaultIMEWnd(NULL); if (IsWindow(hWndDefaultIme)) SendMessage(hWndDefaultIme, WM_IME_SELECT, FALSE, (LPARAM)hUnSelKL); /* * This is the time to update the kernel side layout handles. * We must do this before sending WM_IME_SELECT. */ NtUserSetThreadLayoutHandles(hSelKL, hUnSelKL); /* * Unselect and select input context(s). */ sce.hSelKL = hSelKL; sce.hUnSelKL = hUnSelKL; EnumInputContext(GetCurrentThreadId(), (IMCENUMPROC)SelectContextProc, (LONG)&sce); /* * inform UI select after all hIMC select */ if (IsWindow(hWndDefaultIme)) SendMessage(hWndDefaultIme, WM_IME_SELECT, TRUE, (LPARAM)hSelKL); #ifdef LATER // Do EnumWndProcIMESelect() for old app. support here. #endif return (TRUE); }