| 132 | } |
| 133 | |
| 134 | void KeyCommand::BindString(const char* bind_str) { |
| 135 | KeyEvent events[kMaxKeyEvents]; |
| 136 | enum ParseStage { kInputs, |
| 137 | kCommand }; |
| 138 | ParseStage parse_stage = kInputs; |
| 139 | int num_events = 0; |
| 140 | int i = 0; |
| 141 | int start_token = 0; |
| 142 | std::string str; |
| 143 | std::string display; |
| 144 | str.reserve(255); |
| 145 | display.reserve(255); |
| 146 | while (true) { |
| 147 | char c = bind_str[i]; |
| 148 | if (parse_stage == kInputs) { |
| 149 | if (c == '+' || c == ':') { |
| 150 | if (c == ':') { |
| 151 | parse_stage = kCommand; |
| 152 | } |
| 153 | if (num_events >= kMaxKeyEvents) { |
| 154 | FatalError("Error", "Too many key events in %s", bind_str); |
| 155 | } |
| 156 | // ignore white space at start or end |
| 157 | while (bind_str[start_token] == ' ' || bind_str[start_token] == '\t') { |
| 158 | ++start_token; |
| 159 | } |
| 160 | int end_token = i - 1; |
| 161 | while (bind_str[end_token] == ' ' || bind_str[end_token] == '\t') { |
| 162 | --end_token; |
| 163 | } |
| 164 | // Read token and attempt to parse key name |
| 165 | int token_len = end_token - start_token + 1; |
| 166 | if (CompareSubstr("cmd", &bind_str[start_token], token_len)) { |
| 167 | #ifdef __MACOSX__ |
| 168 | display += "Cmd"; |
| 169 | #else |
| 170 | display += "Ctrl"; |
| 171 | #endif |
| 172 | events[num_events].sc_ = command_SDL_SCANCODE_LEFT_key; |
| 173 | events[num_events].sc2_ = command_SDL_SCANCODE_RIGHT_key; |
| 174 | events[num_events].type_ = kDown; |
| 175 | ++num_events; |
| 176 | } else if (CompareSubstr("shift", &bind_str[start_token], token_len)) { |
| 177 | display += "Shift"; |
| 178 | events[num_events].sc_ = SDL_SCANCODE_LSHIFT; |
| 179 | events[num_events].sc2_ = SDL_SCANCODE_RSHIFT; |
| 180 | events[num_events].type_ = kDown; |
| 181 | ++num_events; |
| 182 | } else if (CompareSubstr("alt", &bind_str[start_token], token_len)) { |
| 183 | #ifdef __MACOSX__ |
| 184 | display += "Option"; |
| 185 | #else |
| 186 | display += "Alt"; |
| 187 | #endif |
| 188 | events[num_events].sc_ = SDL_SCANCODE_LALT; |
| 189 | events[num_events].sc2_ = SDL_SCANCODE_RALT; |
| 190 | events[num_events].type_ = kDown; |
| 191 | ++num_events; |
nothing calls this directly
no test coverage detected