Skip to content

Commit 2193d49

Browse files
committed
Update Ctrl, Alt, Shift in real Update function
Fixes #77 Turns out, if you get sf::Event::Released for Ctrl, Alt, etc. event.key.control/shift/alt won't contain current state of the keyboard, only previous one. So it's better to rely on real time input + now we can handle left/right ctrl/alt/shift being pressed.
1 parent 72df1fd commit 2193d49

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

imgui-SFML.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ void ProcessEvent(const sf::Event& event) {
311311
case sf::Event::KeyReleased:
312312
io.KeysDown[event.key.code] =
313313
(event.type == sf::Event::KeyPressed);
314-
io.KeyCtrl = event.key.control;
315-
io.KeyShift = event.key.shift;
316-
io.KeyAlt = event.key.alt;
317314
break;
318315
case sf::Event::TextEntered:
319316
if (event.text.unicode > 0 && event.text.unicode < 0x10000) {
@@ -397,6 +394,14 @@ void Update(const sf::Vector2i& mousePos, const sf::Vector2f& displaySize,
397394
}
398395
}
399396

397+
// Update Ctrl, Shift, Alt state
398+
io.KeyCtrl = io.KeysDown[sf::Keyboard::LControl] ||
399+
io.KeysDown[sf::Keyboard::RControl];
400+
io.KeyAlt =
401+
io.KeysDown[sf::Keyboard::LAlt] || io.KeysDown[sf::Keyboard::RAlt];
402+
io.KeyShift =
403+
io.KeysDown[sf::Keyboard::LShift] || io.KeysDown[sf::Keyboard::RShift];
404+
400405
#ifdef ANDROID
401406
#ifdef USE_JNI
402407
if (io.WantTextInput && !s_wantTextInput) {

0 commit comments

Comments
 (0)