Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 1 | #include "ikvm_input.hpp" |
| 2 | |
| 3 | #include "ikvm_server.hpp" |
| 4 | |
| 5 | #include <err.h> |
| 6 | #include <errno.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <rfb/keysym.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <sys/types.h> |
| 11 | |
| 12 | #include <phosphor-logging/elog-errors.hpp> |
| 13 | #include <phosphor-logging/elog.hpp> |
| 14 | #include <phosphor-logging/log.hpp> |
| 15 | #include <xyz/openbmc_project/Common/File/error.hpp> |
| 16 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 17 | #include "scancodes.hpp" |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 18 | |
| 19 | namespace ikvm |
| 20 | { |
| 21 | |
| 22 | using namespace phosphor::logging; |
| 23 | using namespace sdbusplus::xyz::openbmc_project::Common::File::Error; |
| 24 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 25 | Input::Input(const std::string& kbdPath, const std::string& ptrPath) : |
Eddie James | 4749f93 | 2019-04-18 11:06:39 -0500 | [diff] [blame] | 26 | pointerError(false), sendKeyboard(false), sendPointer(false), |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 27 | keyboardFd(-1), pointerFd(-1), keyboardReport{0}, pointerReport{0}, |
| 28 | keyboardPath(kbdPath), pointerPath(ptrPath) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 29 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 30 | if (!keyboardPath.empty()) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 31 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 32 | keyboardFd = open(keyboardPath.c_str(), O_RDWR | O_CLOEXEC); |
| 33 | if (keyboardFd < 0) |
| 34 | { |
| 35 | log<level::ERR>("Failed to open input device", |
| 36 | entry("PATH=%s", keyboardPath.c_str()), |
| 37 | entry("ERROR=%s", strerror(errno))); |
| 38 | elog<Open>(xyz::openbmc_project::Common::File::Open::ERRNO(errno), |
| 39 | xyz::openbmc_project::Common::File::Open::PATH( |
| 40 | keyboardPath.c_str())); |
| 41 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 42 | } |
| 43 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 44 | if (!pointerPath.empty()) |
| 45 | { |
Eddie James | 4749f93 | 2019-04-18 11:06:39 -0500 | [diff] [blame] | 46 | pointerFd = open(pointerPath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 47 | if (pointerFd < 0) |
| 48 | { |
| 49 | log<level::ERR>("Failed to open input device", |
| 50 | entry("PATH=%s", pointerPath.c_str()), |
| 51 | entry("ERROR=%s", strerror(errno))); |
| 52 | elog<Open>(xyz::openbmc_project::Common::File::Open::ERRNO(errno), |
| 53 | xyz::openbmc_project::Common::File::Open::PATH( |
| 54 | pointerPath.c_str())); |
| 55 | } |
| 56 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | Input::~Input() |
| 60 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 61 | if (keyboardFd >= 0) |
| 62 | { |
| 63 | close(keyboardFd); |
| 64 | } |
| 65 | |
| 66 | if (pointerFd >= 0) |
| 67 | { |
| 68 | close(pointerFd); |
| 69 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void Input::keyEvent(rfbBool down, rfbKeySym key, rfbClientPtr cl) |
| 73 | { |
| 74 | Server::ClientData* cd = (Server::ClientData*)cl->clientData; |
| 75 | Input* input = cd->input; |
| 76 | |
| 77 | if (down) |
| 78 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 79 | uint8_t sc = keyToScancode(key); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 80 | |
| 81 | if (sc) |
| 82 | { |
| 83 | if (input->keysDown.find(key) == input->keysDown.end()) |
| 84 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 85 | for (unsigned int i = 2; i < KEY_REPORT_LENGTH; ++i) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 86 | { |
| 87 | if (!input->keyboardReport[i]) |
| 88 | { |
| 89 | input->keyboardReport[i] = sc; |
| 90 | input->keysDown.insert(std::make_pair(key, i)); |
| 91 | input->sendKeyboard = true; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | else |
| 98 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 99 | uint8_t mod = keyToMod(key); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 100 | |
| 101 | if (mod) |
| 102 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 103 | input->keyboardReport[0] |= mod; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 104 | input->sendKeyboard = true; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | auto it = input->keysDown.find(key); |
| 111 | |
| 112 | if (it != input->keysDown.end()) |
| 113 | { |
| 114 | input->keyboardReport[it->second] = 0; |
| 115 | input->keysDown.erase(it); |
| 116 | input->sendKeyboard = true; |
| 117 | } |
| 118 | else |
| 119 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 120 | uint8_t mod = keyToMod(key); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 121 | |
| 122 | if (mod) |
| 123 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 124 | input->keyboardReport[0] &= ~mod; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 125 | input->sendKeyboard = true; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | void Input::pointerEvent(int buttonMask, int x, int y, rfbClientPtr cl) |
| 132 | { |
| 133 | Server::ClientData* cd = (Server::ClientData*)cl->clientData; |
| 134 | Input* input = cd->input; |
| 135 | Server* server = (Server*)cl->screen->screenData; |
| 136 | const Video& video = server->getVideo(); |
| 137 | |
Jae Hyun Yoo | 3389098 | 2019-03-19 10:20:27 -0700 | [diff] [blame] | 138 | input->pointerReport[0] = ((buttonMask & 0x4) >> 1) | |
| 139 | ((buttonMask & 0x2) << 1) | (buttonMask & 0x1); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 140 | |
| 141 | if (x >= 0 && (unsigned int)x < video.getWidth()) |
| 142 | { |
Jae Hyun Yoo | 2bc661d | 2019-02-25 13:52:47 -0800 | [diff] [blame] | 143 | uint16_t xx = (uint16_t)(x * (SHRT_MAX + 1) / video.getWidth()); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 144 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 145 | memcpy(&input->pointerReport[1], &xx, 2); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | if (y >= 0 && (unsigned int)y < video.getHeight()) |
| 149 | { |
Jae Hyun Yoo | 2bc661d | 2019-02-25 13:52:47 -0800 | [diff] [blame] | 150 | uint16_t yy = (uint16_t)(y * (SHRT_MAX + 1) / video.getHeight()); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 151 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 152 | memcpy(&input->pointerReport[3], &yy, 2); |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | input->sendPointer = true; |
| 156 | rfbDefaultPtrAddEvent(buttonMask, x, y, cl); |
| 157 | } |
| 158 | |
Eddie James | 23135dd | 2019-08-09 15:41:37 -0500 | [diff] [blame] | 159 | void Input::restart() |
| 160 | { |
| 161 | if (!keyboardPath.empty() && keyboardFd < 0) |
| 162 | { |
| 163 | keyboardFd = open(keyboardPath.c_str(), O_RDWR | O_CLOEXEC); |
| 164 | if (keyboardFd < 0) |
| 165 | { |
| 166 | log<level::ERR>("Failed to open input device", |
| 167 | entry("PATH=%s", keyboardPath.c_str()), |
| 168 | entry("ERROR=%s", strerror(errno))); |
| 169 | } |
| 170 | |
| 171 | sendKeyboard = false; |
| 172 | } |
| 173 | |
| 174 | if (!pointerPath.empty() && pointerFd < 0) |
| 175 | { |
| 176 | pointerFd = open(pointerPath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); |
| 177 | if (pointerFd < 0) |
| 178 | { |
| 179 | log<level::ERR>("Failed to open input device", |
| 180 | entry("PATH=%s", pointerPath.c_str()), |
| 181 | entry("ERROR=%s", strerror(errno))); |
| 182 | } |
| 183 | |
| 184 | pointerError = false; |
| 185 | sendPointer = false; |
| 186 | } |
| 187 | } |
| 188 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 189 | void Input::sendWakeupPacket() |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 190 | { |
Jae Hyun Yoo | eaf5c5b | 2019-02-20 15:03:17 -0800 | [diff] [blame] | 191 | uint8_t wakeupReport[KEY_REPORT_LENGTH] = {0}; |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 192 | |
Jae Hyun Yoo | eaf5c5b | 2019-02-20 15:03:17 -0800 | [diff] [blame] | 193 | if (pointerFd >= 0) |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 194 | { |
Jae Hyun Yoo | eaf5c5b | 2019-02-20 15:03:17 -0800 | [diff] [blame] | 195 | uint16_t xy = SHRT_MAX / 2; |
| 196 | |
| 197 | memcpy(&wakeupReport[1], &xy, 2); |
| 198 | memcpy(&wakeupReport[3], &xy, 2); |
| 199 | |
| 200 | if (write(pointerFd, wakeupReport, PTR_REPORT_LENGTH) != |
| 201 | PTR_REPORT_LENGTH) |
| 202 | { |
| 203 | log<level::ERR>("Failed to write pointer report", |
| 204 | entry("ERROR=%s", strerror(errno))); |
| 205 | } |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Jae Hyun Yoo | eaf5c5b | 2019-02-20 15:03:17 -0800 | [diff] [blame] | 208 | if (keyboardFd >= 0) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 209 | { |
Jae Hyun Yoo | eaf5c5b | 2019-02-20 15:03:17 -0800 | [diff] [blame] | 210 | memset(&wakeupReport[0], 0, KEY_REPORT_LENGTH); |
| 211 | |
| 212 | wakeupReport[0] = keyToMod(XK_Shift_L); |
| 213 | |
| 214 | if (write(keyboardFd, wakeupReport, KEY_REPORT_LENGTH) != |
| 215 | KEY_REPORT_LENGTH) |
| 216 | { |
| 217 | log<level::ERR>("Failed to write keyboard report", |
| 218 | entry("ERROR=%s", strerror(errno))); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | wakeupReport[0] = 0; |
| 223 | |
| 224 | if (write(keyboardFd, wakeupReport, KEY_REPORT_LENGTH) != |
| 225 | KEY_REPORT_LENGTH) |
| 226 | { |
| 227 | log<level::ERR>("Failed to write keyboard report", |
| 228 | entry("ERROR=%s", strerror(errno))); |
| 229 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | void Input::sendReport() |
| 234 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 235 | if (sendKeyboard && keyboardFd >= 0) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 236 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 237 | if (write(keyboardFd, keyboardReport, KEY_REPORT_LENGTH) != |
| 238 | KEY_REPORT_LENGTH) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 239 | { |
| 240 | log<level::ERR>("Failed to write keyboard report", |
| 241 | entry("ERROR=%s", strerror(errno))); |
Eddie James | 23135dd | 2019-08-09 15:41:37 -0500 | [diff] [blame] | 242 | |
| 243 | if (errno == ESHUTDOWN) |
| 244 | { |
| 245 | close(keyboardFd); |
| 246 | keyboardFd = -1; |
| 247 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | sendKeyboard = false; |
| 251 | } |
| 252 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 253 | if (sendPointer && pointerFd >= 0) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 254 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 255 | if (write(pointerFd, pointerReport, PTR_REPORT_LENGTH) != |
| 256 | PTR_REPORT_LENGTH) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 257 | { |
Eddie James | 4749f93 | 2019-04-18 11:06:39 -0500 | [diff] [blame] | 258 | if (!pointerError) |
| 259 | { |
| 260 | log<level::ERR>("Failed to write pointer report", |
| 261 | entry("ERROR=%s", strerror(errno))); |
| 262 | pointerError = true; |
| 263 | } |
Eddie James | 23135dd | 2019-08-09 15:41:37 -0500 | [diff] [blame] | 264 | |
| 265 | if (errno == ESHUTDOWN) |
| 266 | { |
| 267 | close(pointerFd); |
| 268 | pointerFd = -1; |
| 269 | } |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | pointerError = false; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | sendPointer = false; |
| 277 | } |
| 278 | } |
| 279 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 280 | uint8_t Input::keyToMod(rfbKeySym key) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 281 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 282 | uint8_t mod = 0; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 283 | |
| 284 | if (key >= XK_Shift_L && key <= XK_Control_R) |
| 285 | { |
| 286 | mod = shiftCtrlMap[key - XK_Shift_L]; |
| 287 | } |
| 288 | else if (key >= XK_Meta_L && key <= XK_Alt_R) |
| 289 | { |
| 290 | mod = metaAltMap[key - XK_Meta_L]; |
| 291 | } |
| 292 | |
| 293 | return mod; |
| 294 | } |
| 295 | |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 296 | uint8_t Input::keyToScancode(rfbKeySym key) |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 297 | { |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 298 | uint8_t scancode = 0; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 299 | |
| 300 | if ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) |
| 301 | { |
| 302 | scancode = USBHID_KEY_A + ((key & 0x5F) - 'A'); |
| 303 | } |
| 304 | else if (key >= '1' && key <= '9') |
| 305 | { |
| 306 | scancode = USBHID_KEY_1 + (key - '1'); |
| 307 | } |
| 308 | else if (key >= XK_F1 && key <= XK_F12) |
| 309 | { |
| 310 | scancode = USBHID_KEY_F1 + (key - XK_F1); |
| 311 | } |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 312 | else if (key >= XK_KP_F1 && key <= XK_KP_F4) |
| 313 | { |
| 314 | scancode = USBHID_KEY_F1 + (key - XK_KP_F1); |
| 315 | } |
| 316 | else if (key >= XK_KP_1 && key <= XK_KP_9) |
| 317 | { |
| 318 | scancode = USBHID_KEY_KP_1 + (key - XK_KP_1); |
| 319 | } |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 320 | else |
| 321 | { |
| 322 | switch (key) |
| 323 | { |
| 324 | case XK_exclam: |
| 325 | scancode = USBHID_KEY_1; |
| 326 | break; |
| 327 | case XK_at: |
| 328 | scancode = USBHID_KEY_2; |
| 329 | break; |
| 330 | case XK_numbersign: |
| 331 | scancode = USBHID_KEY_3; |
| 332 | break; |
| 333 | case XK_dollar: |
| 334 | scancode = USBHID_KEY_4; |
| 335 | break; |
| 336 | case XK_percent: |
| 337 | scancode = USBHID_KEY_5; |
| 338 | break; |
| 339 | case XK_asciicircum: |
| 340 | scancode = USBHID_KEY_6; |
| 341 | break; |
| 342 | case XK_ampersand: |
| 343 | scancode = USBHID_KEY_7; |
| 344 | break; |
| 345 | case XK_asterisk: |
| 346 | scancode = USBHID_KEY_8; |
| 347 | break; |
| 348 | case XK_parenleft: |
| 349 | scancode = USBHID_KEY_9; |
| 350 | break; |
| 351 | case XK_0: |
| 352 | case XK_parenright: |
| 353 | scancode = USBHID_KEY_0; |
| 354 | break; |
| 355 | case XK_Return: |
| 356 | scancode = USBHID_KEY_RETURN; |
| 357 | break; |
| 358 | case XK_Escape: |
| 359 | scancode = USBHID_KEY_ESC; |
| 360 | break; |
| 361 | case XK_BackSpace: |
| 362 | scancode = USBHID_KEY_BACKSPACE; |
| 363 | break; |
| 364 | case XK_Tab: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 365 | case XK_KP_Tab: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 366 | scancode = USBHID_KEY_TAB; |
| 367 | break; |
| 368 | case XK_space: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 369 | case XK_KP_Space: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 370 | scancode = USBHID_KEY_SPACE; |
| 371 | break; |
| 372 | case XK_minus: |
| 373 | case XK_underscore: |
| 374 | scancode = USBHID_KEY_MINUS; |
| 375 | break; |
| 376 | case XK_plus: |
| 377 | case XK_equal: |
| 378 | scancode = USBHID_KEY_EQUAL; |
| 379 | break; |
| 380 | case XK_bracketleft: |
| 381 | case XK_braceleft: |
| 382 | scancode = USBHID_KEY_LEFTBRACE; |
| 383 | break; |
| 384 | case XK_bracketright: |
| 385 | case XK_braceright: |
| 386 | scancode = USBHID_KEY_RIGHTBRACE; |
| 387 | break; |
| 388 | case XK_backslash: |
| 389 | case XK_bar: |
| 390 | scancode = USBHID_KEY_BACKSLASH; |
| 391 | break; |
| 392 | case XK_colon: |
| 393 | case XK_semicolon: |
| 394 | scancode = USBHID_KEY_SEMICOLON; |
| 395 | break; |
| 396 | case XK_quotedbl: |
| 397 | case XK_apostrophe: |
| 398 | scancode = USBHID_KEY_APOSTROPHE; |
| 399 | break; |
| 400 | case XK_grave: |
| 401 | case XK_asciitilde: |
| 402 | scancode = USBHID_KEY_GRAVE; |
| 403 | break; |
| 404 | case XK_comma: |
| 405 | case XK_less: |
| 406 | scancode = USBHID_KEY_COMMA; |
| 407 | break; |
| 408 | case XK_period: |
| 409 | case XK_greater: |
| 410 | scancode = USBHID_KEY_DOT; |
| 411 | break; |
| 412 | case XK_slash: |
| 413 | case XK_question: |
| 414 | scancode = USBHID_KEY_SLASH; |
| 415 | break; |
| 416 | case XK_Caps_Lock: |
| 417 | scancode = USBHID_KEY_CAPSLOCK; |
| 418 | break; |
| 419 | case XK_Print: |
| 420 | scancode = USBHID_KEY_PRINT; |
| 421 | break; |
| 422 | case XK_Scroll_Lock: |
| 423 | scancode = USBHID_KEY_SCROLLLOCK; |
| 424 | break; |
| 425 | case XK_Pause: |
| 426 | scancode = USBHID_KEY_PAUSE; |
| 427 | break; |
| 428 | case XK_Insert: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 429 | case XK_KP_Insert: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 430 | scancode = USBHID_KEY_INSERT; |
| 431 | break; |
| 432 | case XK_Home: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 433 | case XK_KP_Home: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 434 | scancode = USBHID_KEY_HOME; |
| 435 | break; |
| 436 | case XK_Page_Up: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 437 | case XK_KP_Page_Up: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 438 | scancode = USBHID_KEY_PAGEUP; |
| 439 | break; |
| 440 | case XK_Delete: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 441 | case XK_KP_Delete: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 442 | scancode = USBHID_KEY_DELETE; |
| 443 | break; |
| 444 | case XK_End: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 445 | case XK_KP_End: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 446 | scancode = USBHID_KEY_END; |
| 447 | break; |
| 448 | case XK_Page_Down: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 449 | case XK_KP_Page_Down: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 450 | scancode = USBHID_KEY_PAGEDOWN; |
| 451 | break; |
| 452 | case XK_Right: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 453 | case XK_KP_Right: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 454 | scancode = USBHID_KEY_RIGHT; |
| 455 | break; |
| 456 | case XK_Left: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 457 | case XK_KP_Left: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 458 | scancode = USBHID_KEY_LEFT; |
| 459 | break; |
| 460 | case XK_Down: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 461 | case XK_KP_Down: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 462 | scancode = USBHID_KEY_DOWN; |
| 463 | break; |
| 464 | case XK_Up: |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 465 | case XK_KP_Up: |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 466 | scancode = USBHID_KEY_UP; |
| 467 | break; |
| 468 | case XK_Num_Lock: |
| 469 | scancode = USBHID_KEY_NUMLOCK; |
| 470 | break; |
Jae Hyun Yoo | 513d95e | 2019-08-20 11:26:53 -0700 | [diff] [blame^] | 471 | case XK_KP_Enter: |
| 472 | scancode = USBHID_KEY_KP_ENTER; |
| 473 | break; |
| 474 | case XK_KP_Equal: |
| 475 | scancode = USBHID_KEY_KP_EQUAL; |
| 476 | break; |
| 477 | case XK_KP_Multiply: |
| 478 | scancode = USBHID_KEY_KP_MULTIPLY; |
| 479 | break; |
| 480 | case XK_KP_Add: |
| 481 | scancode = USBHID_KEY_KP_ADD; |
| 482 | break; |
| 483 | case XK_KP_Subtract: |
| 484 | scancode = USBHID_KEY_KP_SUBTRACT; |
| 485 | break; |
| 486 | case XK_KP_Decimal: |
| 487 | scancode = USBHID_KEY_KP_DECIMAL; |
| 488 | break; |
| 489 | case XK_KP_Divide: |
| 490 | scancode = USBHID_KEY_KP_DIVIDE; |
| 491 | break; |
| 492 | case XK_KP_0: |
| 493 | scancode = USBHID_KEY_KP_0; |
| 494 | break; |
Eddie James | 21b177e | 2018-12-11 13:14:46 -0600 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | return scancode; |
| 499 | } |
| 500 | |
| 501 | } // namespace ikvm |