|
57 | 57 | #include <sys/ioctl.h> // Required for: ioctl() - UNIX System call for device-specific input/output operations
|
58 | 58 | #include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
59 | 59 | #include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
|
| 60 | + |
| 61 | +// So both `linux/input.h` and `raylib.h` define KEY_F12 |
| 62 | +// To avoid conflict with the capturing code in rcore.c we undefine the macro KEY_F12, |
| 63 | +// so the enum KEY_F12 from raylib is used |
| 64 | +#undef KEY_F12 |
| 65 | + |
60 | 66 | #include <linux/joystick.h> // Linux: Joystick support library
|
61 | 67 |
|
62 | 68 | #include <gbm.h> // Generic Buffer Management (native platform for EGL on DRM)
|
@@ -548,6 +554,16 @@ void PollInputEvents(void)
|
548 | 554 |
|
549 | 555 | PollKeyboardEvents();
|
550 | 556 |
|
| 557 | + #if defined(SUPPORT_SSH_KEYBOARD_RPI) |
| 558 | + // NOTE: Keyboard reading could be done using input_event(s) or just read from stdin, both methods are used here. |
| 559 | + // stdin reading is still used for legacy purposes, it allows keyboard input trough SSH console |
| 560 | + |
| 561 | + if (!platform.eventKeyboardMode) ProcessKeyboard(); |
| 562 | + #endif |
| 563 | + |
| 564 | + // Check exit key |
| 565 | + if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; |
| 566 | + |
551 | 567 | // Register previous mouse position
|
552 | 568 | if (platform.cursorRelative) CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
|
553 | 569 | else CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
|
@@ -575,13 +591,6 @@ void PollInputEvents(void)
|
575 | 591 | // Map touch position to mouse position for convenience
|
576 | 592 | CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
|
577 | 593 |
|
578 |
| -#if defined(SUPPORT_SSH_KEYBOARD_RPI) |
579 |
| - // NOTE: Keyboard reading could be done using input_event(s) or just read from stdin, both methods are used here. |
580 |
| - // stdin reading is still used for legacy purposes, it allows keyboard input trough SSH console |
581 |
| - |
582 |
| - if (!platform.eventKeyboardMode) ProcessKeyboard(); |
583 |
| -#endif |
584 |
| - |
585 | 594 | // Handle the mouse/touch/gestures events:
|
586 | 595 | // NOTE: Replaces the EventThread handling that is now commented.
|
587 | 596 | PollMouseEvents();
|
@@ -1206,18 +1215,6 @@ static void ProcessKeyboard(void)
|
1206 | 1215 | CORE.Input.Keyboard.keyPressedQueueCount++;
|
1207 | 1216 | }
|
1208 | 1217 | }
|
1209 |
| - |
1210 |
| - // Check exit key (same functionality as GLFW3 KeyCallback()) |
1211 |
| - if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; |
1212 |
| - |
1213 |
| -#if defined(SUPPORT_SCREEN_CAPTURE) |
1214 |
| - // Check screen capture key (raylib key: KEY_F12) |
1215 |
| - if (CORE.Input.Keyboard.currentKeyState[301] == 1) |
1216 |
| - { |
1217 |
| - TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter)); |
1218 |
| - screenshotCounter++; |
1219 |
| - } |
1220 |
| -#endif |
1221 | 1218 | }
|
1222 | 1219 | #endif // SUPPORT_SSH_KEYBOARD_RPI
|
1223 | 1220 |
|
@@ -1470,57 +1467,47 @@ static void PollKeyboardEvents(void)
|
1470 | 1467 | // Try to read data from the keyboard and only continue if successful
|
1471 | 1468 | while (read(fd, &event, sizeof(event)) == (int)sizeof(event))
|
1472 | 1469 | {
|
1473 |
| - // Button parsing |
1474 |
| - if (event.type == EV_KEY) |
1475 |
| - { |
| 1470 | + // Check if the event is a key event |
| 1471 | + if (event.type != EV_KEY) continue; |
| 1472 | + |
1476 | 1473 | #if defined(SUPPORT_SSH_KEYBOARD_RPI)
|
1477 |
| - // Change keyboard mode to events |
1478 |
| - platform.eventKeyboardMode = true; |
| 1474 | + // If the event was a key, we know a working keyboard is connected, so disable the SSH keyboard |
| 1475 | + platform.eventKeyboardMode = true; |
1479 | 1476 | #endif
|
1480 |
| - // Keyboard button parsing |
1481 |
| - if ((event.code >= 1) && (event.code <= 255)) //Keyboard keys appear for codes 1 to 255 |
1482 |
| - { |
1483 |
| - keycode = keymapUS[event.code & 0xFF]; // The code we get is a scancode so we look up the appropriate keycode |
1484 | 1477 |
|
1485 |
| - // Make sure we got a valid keycode |
1486 |
| - if ((keycode > 0) && (keycode < sizeof(CORE.Input.Keyboard.currentKeyState))) |
| 1478 | + // Keyboard keys appear for codes 1 to 255, ignore everthing else |
| 1479 | + if ((event.code >= 1) && (event.code <= 255)) { |
| 1480 | + |
| 1481 | + // Lookup the scancode in the keymap to get a keycode |
| 1482 | + keycode = keymapUS[event.code]; |
| 1483 | + |
| 1484 | + // Make sure we got a valid keycode |
| 1485 | + if ((keycode > 0) && (keycode < MAX_KEYBOARD_KEYS)) { |
| 1486 | + |
| 1487 | + // WARNING: https://www.kernel.org/doc/Documentation/input/input.txt |
| 1488 | + // Event interface: 'value' is the value the event carries. Either a relative change for EV_REL, |
| 1489 | + // absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat |
| 1490 | + CORE.Input.Keyboard.currentKeyState[keycode] = (event.value >= 1); |
| 1491 | + CORE.Input.Keyboard.keyRepeatInFrame[keycode] = (event.value == 2); |
| 1492 | + |
| 1493 | + // If the key is pressed add it to the queues |
| 1494 | + if (event.value == 1) |
1487 | 1495 | {
|
1488 |
| - // WARNING: https://www.kernel.org/doc/Documentation/input/input.txt |
1489 |
| - // Event interface: 'value' is the value the event carries. Either a relative change for EV_REL, |
1490 |
| - // absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat |
1491 |
| - CORE.Input.Keyboard.currentKeyState[keycode] = (event.value >= 1)? 1 : 0; |
1492 |
| - CORE.Input.Keyboard.keyRepeatInFrame[keycode] = (event.value == 2)? 1 : 0; |
1493 |
| - if (event.value >= 1) |
| 1496 | + if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
1494 | 1497 | {
|
1495 |
| - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; // Register last key pressed |
| 1498 | + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; |
1496 | 1499 | CORE.Input.Keyboard.keyPressedQueueCount++;
|
1497 | 1500 | }
|
1498 | 1501 |
|
1499 |
| - #if defined(SUPPORT_SCREEN_CAPTURE) |
1500 |
| - // Check screen capture key (raylib key: KEY_F12) |
1501 |
| - if (CORE.Input.Keyboard.currentKeyState[301] == 1) |
| 1502 | + if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
1502 | 1503 | {
|
1503 |
| - TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter)); |
1504 |
| - screenshotCounter++; |
| 1504 | + // TODO/FIXME: This is not actually converting to unicode properly because it's not taking things like shift into account |
| 1505 | + CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = EvkeyToUnicodeLUT[event.code]; |
| 1506 | + CORE.Input.Keyboard.charPressedQueueCount++; |
1505 | 1507 | }
|
1506 |
| - #endif |
1507 |
| - |
1508 |
| - // Detect char presses (unicode) |
1509 |
| - if (event.value == 1) |
1510 |
| - { |
1511 |
| - // Check if there is space available in the queue |
1512 |
| - if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
1513 |
| - { |
1514 |
| - // Add character to the queue |
1515 |
| - CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = EvkeyToUnicodeLUT[event.code]; |
1516 |
| - CORE.Input.Keyboard.charPressedQueueCount++; |
1517 |
| - } |
1518 |
| - } |
1519 |
| - |
1520 |
| - if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; |
1521 |
| - |
1522 |
| - TRACELOGD("DRM: KEY_%s ScanCode: %4i KeyCode: %4i", (event.value == 0)? "UP" : "DOWN", event.code, keycode); |
1523 | 1508 | }
|
| 1509 | + |
| 1510 | + TRACELOG(LOG_DEBUG, "DRM: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0) ? "UP " : "DOWN", event.code, keycode); |
1524 | 1511 | }
|
1525 | 1512 | }
|
1526 | 1513 | }
|
|
0 commit comments