Repository: libsdl-org/SDL
File: src/events/SDL_keyboard.c (C)

Code before:
                    keyboard->keysource[scancode] |= source;
                    return false;
                }
                repeat = true;
            }
            keyboard->keysource[scancode] |= source;
        } else {
            if (keyboard->keyrefcount[scancode] == 0) {
                return false; //Early out
            }
            keyboard->keyrefcount[scancode]--;
            if (keyboard->keyrefcount[scancode] == 0) {
                keyboard->keysource[scancode] = 0;
                last_release = true;
            } else {
                last_release = false;
            }
        }

        // Update internal keyboard state
        if (down) {
            keyboard->keystate[scancode] = true;
        } else {
            if (keyboard->keyrefcount[scancode] == 0) {
                keyboard->keystate[scancode] = false;
            }
        }

        keycode = SDL_GetKeyFromScancode(scancode, keyboard->modstate, true);

    } else if (rawcode == 0) {
        // Nothing to do!
        return false;
    }

    if (source == KEYBOARD_HARDWARE) {
        keyboard->hardware_timestamp = SDL_GetTicks();
    } else if (source == KEYBOARD_AUTORELEASE) {
        keyboard->autorelease_pending = true;
    }

    // Update modifiers state if applicable
    if (!(flags & KEYBOARD_IGNOREMODIFIERS) && !repeat) {
        SDL_Keymod modifier;

        switch (keycode) {
        case SDLK_LCTRL:
            modifier = SDL_KMOD_LCTRL;
            break;
        case SDLK_RCTRL:
            modifier = SDL_KMOD_RCTRL;

Review comment (suggestion):
```suggestion
        } else if (last_release) {
            keyboard->keystate[scancode] = false;
```

Code after:
                    keyboard->keysource[scancode] |= source;
                    return false;
                }
                repeat = true;
            }
            keyboard->keysource[scancode] |= source;
        } else {
            if (keyboard->keyrefcount[scancode] == 0) {
                return false;
            }
            --keyboard->keyrefcount[scancode];
            if (keyboard->keyrefcount[scancode] == 0) {
                keyboard->keysource[scancode] = 0;
                last_release = true;
            }
        }

        // Update internal keyboard state
        if (down) {
            keyboard->keystate[scancode] = true;
        } else if (last_release) {
            keyboard->keystate[scancode] = false;
        }

        keycode = SDL_GetKeyFromScancode(scancode, keyboard->modstate, true);

    } else if (rawcode == 0) {
        // Nothing to do!
        return false;
    }

    if (source == KEYBOARD_HARDWARE) {
        keyboard->hardware_timestamp = SDL_GetTicks();
    } else if (source == KEYBOARD_AUTORELEASE) {
        keyboard->autorelease_pending = true;
    }

    // Update modifiers state if applicable
    if (!(flags & KEYBOARD_IGNOREMODIFIERS) && !repeat) {
        SDL_Keymod modifier;

        switch (keycode) {
        case SDLK_LCTRL:
            modifier = SDL_KMOD_LCTRL;
            break;
        case SDLK_RCTRL:
            modifier = SDL_KMOD_RCTRL;
            break;
        case SDLK_LSHIFT:
            modifier = SDL_KMOD_LSHIFT;
            break;