# Shift (and ctrl) keyboard state gets "stuck" with ImGui

**URL:** <https://discourse.libcinder.org/t/shift-and-ctrl-keyboard-state-gets-stuck-with-imgui/2067>\
**Category:** Using Cinder\
**Created:** [January 25, 2023, 6:09pm UTC](https://discourse.libcinder.org/t/shift-and-ctrl-keyboard-state-gets-stuck-with-imgui/2067 "2023-01-25T18:09:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![totalgee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/totalgee/32/274_2.png) [@totalgee](https://discourse.libcinder.org/u/totalgee)\
**Post date:** [January 25, 2023, 6:09pm UTC](https://discourse.libcinder.org/t/shift-and-ctrl-keyboard-state-gets-stuck-with-imgui/2067/1 "2023-01-25T18:09:02Z")

</div>

Hi there, I’m finding something weird. In my Cinder app that uses ImGui, I find the shift (and also ctrl) keyboard state can get “stuck”. I’ve traced through some of the code, and I found something strange…

When I press **left shift** , on the keyDown (`ImGui_ImplCinder_KeyDown()`) I have key code 304 being pressed down, and then the same code being released in keyUp (`ImGui_ImplCinder_KeyUp()`). When I press the **right shift** key, I get keyDown of 303, followed by a keyUp of 303, as expected. But it seems like there’s some sort of toggle, because the **next** time I press right shift key, I still get keyDown of 303 (as before), but the subsequent keyUp has code 304 (corresponding to left shift)! This means the internal `io.KeysDown` array gets messed up.

I see something similar with left/right control keys, I always get down/up codes of 306 for left ctrl, but for right ctrl I get down and up of code 305 one time, then down of 305 and up of 306 the next time I press/release.

There must be some weird remapping of right to left, but only every second time…? Can anybody reproduce this? I’m on Windows with a fairly recent `master` branch of Cinder.

Thanks,  
Glen.

---

<div class="post-metadata">

**Author:** ![totalgee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/totalgee/32/274_2.png) [@totalgee](https://discourse.libcinder.org/u/totalgee)\
**Post date:** [January 26, 2023, 10:33am UTC](https://discourse.libcinder.org/t/shift-and-ctrl-keyboard-state-gets-stuck-with-imgui/2067/2 "2023-01-26T10:33:12Z")

</div>

I haven’t figured out why we get this weird behaviour (where right shift/ctrl keys sometimes send different key codes on `KeyDown` vs `KeyUp`), but at least I solved my problems by using a better way of getting modifier state from ImGui. I now use this simpler condition:

```auto
ui::GetIO().KeyShift // or KeyCtrl, as appropriate

```

rather than what I used to check:

```auto
ui::IsKeyDown(app::KeyEvent::KEY_LSHIFT) || ui::IsKeyDown(app::KeyEvent::KEY_RSHIFT)

```

So, my bad, I guess. (Although the down/up key code issue is still mysterious…)
