Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State of modifier keys is wrong in certain scenarios #174

Closed
s-p-k-m opened this issue Jun 6, 2021 · 1 comment · Fixed by #197
Closed

State of modifier keys is wrong in certain scenarios #174

s-p-k-m opened this issue Jun 6, 2021 · 1 comment · Fixed by #197
Labels

Comments

@s-p-k-m
Copy link

s-p-k-m commented Jun 6, 2021

I'm not sure if the root cause is within SFML itself or imgui-SFML, but you can observe the following behavior:

  1. Create a combobox with enough items so that the dropdown list has a scrollbar. Or simply use ImGui::ShowDemoWindow().
  2. Open the combobox, now you can use the mousewheel to scroll through the droplist.
  3. Press Ctrl once.
  4. Now scrolling through the droplist via mousewheel no longer works.
  5. Press any "normal" key (like a letter).
  6. Scrolling works again.

The problem is within ProcessEvent(), which sets the keystate with io.KeyCtrl = event.key.control;. However, event.key.control seems to contain the wrong state in this scenario, probably because in this scenario Ctrl is treated as normal key and not as modifier key in combination with another key like e.g. Ctrl+C.
Pressing a "normal" key afterwards resets io.KeyCtrl again, so scrolling works again.
As mentioned, I'm not sure if this isn't an issue within SFML itself.

This scenario is particularly annoying to me because I have an application where I use Ctrl+Mousewheel to zoom in/out. So it is commonly used and afterwards the comboboxes don't work correctly anymore because the of this.

A rather crude fix that works for me is to replace io.KeyCtrl = event.key.control; with:

if( (event.key.code == sf::Keyboard::LControl) || (event.key.code == sf::Keyboard::RControl) )
{
  io.KeyCtrl = (event.type == sf::Event::KeyPressed);
}
else
{
  io.KeyCtrl = event.key.control;
}

I have only checked with the Ctrl key, but I assume other modifiers like Alt or Shift suffer from the same problem.

@eliasdaler eliasdaler added the bug label Aug 14, 2021
@oprypin
Copy link
Member

oprypin commented Mar 29, 2022

I confirm that this issue happens as described. #197 will fix it

oprypin@8c25c15#diff-af3a8a65ddb03c9f3bc2d2ce0994379a9e854b9389e0d945ef3f48449d9d3dfbR599

And indeed the idea for the fix I came up with is the same as what you're suggesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants