Skip to content

State of modifier keys is wrong in certain scenarios #174

@s-p-k-m

Description

@s-p-k-m

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions