| 78 | } |
| 79 | |
| 80 | void WinapiHandler::LoadAvailableLayouts() { |
| 81 | HKEY key; |
| 82 | if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
| 83 | TEXT("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts"), |
| 84 | 0, KEY_ENUMERATE_SUB_KEYS|KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { |
| 85 | TCHAR hkl_string[MAX_KEY_LENGTH]; // Buffer for subkey name. |
| 86 | DWORD key_name_size; // Size of name string. |
| 87 | DWORD nb_subkeys = 0; // Number of subkeys (layouts). |
| 88 | TCHAR layout_name[MAX_LAYOUT_NAME_LENGTH]; // Buffer for layout name. |
| 89 | |
| 90 | DWORD ret_code; |
| 91 | // Get the number of layouts. |
| 92 | ret_code = RegQueryInfoKey(key, // Key handle. |
| 93 | NULL, // Buffer for class name. |
| 94 | NULL, // Size of class string. |
| 95 | NULL, // Reserved. |
| 96 | &nb_subkeys, // Number of subkeys. |
| 97 | NULL, // Longest subkey size. |
| 98 | NULL, // Longest class string. |
| 99 | NULL, // Number of values for this key. |
| 100 | NULL, // Longest value name. |
| 101 | NULL, // Longest value data. |
| 102 | NULL, // Security descriptor. |
| 103 | NULL); // Last write time. |
| 104 | |
| 105 | if (ret_code == ERROR_SUCCESS) { |
| 106 | // Enumerate the subkeys, until RegEnumKeyEx fails. |
| 107 | if (nb_subkeys > 0) { |
| 108 | keyboard_layouts.clear(); |
| 109 | keyboard_layouts.reserve(nb_subkeys); |
| 110 | |
| 111 | for (unsigned int i = 0; i < nb_subkeys; i++) { |
| 112 | key_name_size = MAX_KEY_LENGTH; |
| 113 | ret_code = RegEnumKeyEx(key, i, hkl_string, &key_name_size, |
| 114 | NULL, NULL, NULL, NULL); |
| 115 | if (ret_code == ERROR_SUCCESS) { |
| 116 | DWORD nb_bytes = sizeof(layout_name); |
| 117 | if (RegGetValue(key, hkl_string, "Layout Text", RRF_RT_ANY, NULL, |
| 118 | &layout_name, &nb_bytes) == ERROR_SUCCESS) { |
| 119 | keyboard_layout k = keyboard_layout(hkl_string, layout_name); |
| 120 | keyboard_layouts.push_back(k); |
| 121 | } else { |
| 122 | std::cerr << "error getting key modifiers" << std::endl; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | RegCloseKey(key); |
| 128 | } else { |
| 129 | std::cerr << "could not access the registry" << std::endl; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Returns the name of the engine currently active. |